Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unity 2020.3.30f1 Exporting a prefab from Project will result in missing animations. #745

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion Runtime/Scripts/SceneExporter/ExporterAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ private void ConvertClipToGLTFAnimation(AnimationClip clip, Transform transform,
Transform targetTr = target.Length > 0 ? transform.Find(target) : transform;
int newTargetId = targetTr ? GetTransformIndex(targetTr) : -1;

var targetTrShouldNotBeExported = targetTr && !targetTr.gameObject.activeInHierarchy && !settings.ExportDisabledGameObjects;
var targetTrShouldNotBeExported = !ShouldTargetBeExported(targetTr);

if (hadAlreadyExportedThisBindingBefore && newTargetId < 0)
{
Expand Down Expand Up @@ -1191,6 +1191,23 @@ private void CollectClipCurves(GameObject root, AnimationClip clip, Dictionary<s
#endif
}

private bool ShouldTargetBeExported(Transform transform)
{
if (!transform) return false;
if (settings.ExportDisabledGameObjects) return true;

//Custom activeInHierarchy check.
//gameObject.activeInHierarchy will return false if the GameObject is a prefab and not instantiated in the scene
var root = transform.root;
var current = transform;
while (current != root)
{
if (!current.gameObject.activeSelf) return false;
current = current.parent;
}
return true;
}

private void GenerateMissingCurves(float endTime, Transform tr, ref Dictionary<string, TargetCurveSet> targetCurvesBinding)
{
var keyList = targetCurvesBinding.Keys.ToList();
Expand Down