Hi to all!
This is probably a which-script-runs-before-which-script typpa timing problem.
- I have a UI gameobject, the scale is set to Vector.One
- Animator with Animation that scales gameobject from Vector.Zero to Vector.One is attached
- We have a script in the screen that Instantiate this gameobject (prefab)
- the object is instantiated with scale == Vector.One and animation kick in next frame and start scaling the object from Vector.Zero to Vector.One.
On initialize: Vector.One
Next frame: Vector.Zero
Next frame: Vector.0.3
Next frame: Vector.0.6
Next frame: Vector.One
Something like this.
I think this is the exact problem :
Animated character appears in T Pose in its first frame - Questions & Answers - Unity Discussions
I had the exact same problem in other projects too.
Since I canāt get the values from Animation curves at frame 0 at runtime, this is how Iāve been patching / initializing it on Awake.
anim.Update( 0f );
anim.enabled = false;
Everything works fine till last week, my colleague received a new prefab from designer that uses different Animator & Animation and we start gettingā¦
Assertion failed: Assertion failed on expression: ām_DidAwakeā
UnityEngine.AnimationClip:Update( float deltaTime )
Iām pretty sure this is a timing issue cause thereās no āT-pose situationā and it plays fine afterwards if I removed the anim.Update(0) call.
Then I start digging, observing and comparing the differences between the OK and not-OK animatorsā values, trying to find a hidden flag or something so that I can decide whether to call Update(0) or not on Awake.
I had no luck, values seem identical.
I then tried, anim.runtimeAnimatorController.animationClips[0].SampleAnimation( gameObject, 0 );
It gives me the same m_DidAwake assertion.
anim.Play( anim.runtimeAnimatorController.animationClips[0].name, 0, 0 );
No m_DidAwake assertion, but gives you the t-pose.
Iām outta options,
The only patch I can think of isā¦
- provide a bool flag in the animator.
- white a editor script to store frame 0 values from Animation curves when designer hit āApplyā and use those values for initializing later at runtime.
Method 1⦠too manual. Method 2⦠extra step + many prefab needs to be re-apply and there must be a easier way and I think Unity should provide a fix not us fumbling around.
Regards,
edit:
btw, Iām running Unity 2017.2.0p2