- Home /
anchoredPosition in mechanim locks my axis
Hello,
I have a UI Text object. I affect it in several ways:
I move it down with mechanim affecting its pivot
I scale is up and down several times using mechanim affecting it's scale
I shake it (move it inside unitSphere on y/x axis) with the below script
void Update () { ShakeStandBy (); } void ShakeStandBy() { if(shakeIntensity > 0) { transform.position = originalPosition + Random.insideUnitSphere * shakeIntensity; shakeIntensity -= shakeDecay; } else { transform.position = originalPosition; } }
"1.", "2." and "3." all work fine on their own.
Here's the problem: In "2." I also need to affect the anchoredPosition because by that time the text is moved with "1." and its pivot is modified, so to counter that I also affect anchoredPosition in my scaling animation which gives the desired effect - the text is scaled from its CENTER and remains in the desired location. If I were to counter this effect by affecting pivot instead, the scaling would not happen from the center but from the top (since I moved the Text DOWN).
As soon as I use anchoredPosition in my animation, the shake stops working on the y axis as if it's locked and only works on x axis. I don't even have to run that animation, it's sufficient to have a state in the animator with this animation (that affects anchoredPosition somehow) plugged in, and the shake won't work. If you unplug it, it's works normally again.
I tried rewriting the shake function with GetComponent().anchoredPosition but I get the same result. I spent the entire day trying various workarounds and nothing solves this issue.
Does anyone know why do I get such behaviour?
Thanks in advance.
Answer by curiouspers · Mar 24, 2015 at 06:22 PM
Yup, mecanim just works this way, move your ShakeStadBy() call to LateUpdate instead of regular Update. I fixed my animation problems this way. And this maybe interesting: http://docs.unity3d.com/Manual/ExecutionOrder.html This is for 2) and 3).
For 1) and 2) you can also try using animation layers and play with override value.
You know what the funniest thing is? I have that picture of the execution order on my desktop for 3-4 months already. And I got so used to it being there that I stopped perceiving that it actually holds any kind of information and by the gods man did you save me a lot of further guesswork.
Thank you!
Still, It's very weird and uncomfortable that if I have ANY animation in mechanim affecting ANYTHING, that THING will be locked in place and I won't be able to manipulate it unless it's in LateUpdate and sometimes I even have to manually disable the animator so it doesn't snap the position/scale/whatever back to it's place as soon as the action in LateUpdate is finished. It looks like a bug. I mean if the animation is not playing at that moment, why the hell are its values (whatever it animates) locked in place?? This looks like a bug to me
Your answer
Follow this Question
Related Questions
GetComponent() Problem with getting value. 1 Answer
How to animate UI rect transform which works for all resolutions 1 Answer
Reusing SpriteRenderer animations in UI 0 Answers
Fill empty space in parent in UI Layout 1 Answer
How to change the Top and Bottom (rect.yMin and yMax) properties of a rectTransform, in a script? 2 Answers