- Home /
Changing position of GameObject with Animation
Hello,
I am having problem with dynamic change of GameObject position (e.g. transform.position,...) which has attached animation(s) to it. It doesn´t do anything.
It seems like the existing animation(s) override my commands for position change, even if these animations are not being played.
Once I delete all existing animations of the GameObject, I can change its position again as expected.
Is this behaviour to be expected? How do I get around it?
Thank you all for your thoughts!
George
Any chance to share your code to see how the transform.position is called and animations.
Also are you using mecanim, or the legacy animation system?
The code is: myGameObject.transform.position = Vector3(0,1,2);
This doesn´t work as long as animations are attached to it through Animator - I guess that´s mecanim?
As a guess, it seems you may be using $$anonymous$$ecanim. WIth the GameObject selected, In the inspector Window, Under the Animator Component. Try disabling "Apply Root $$anonymous$$otion" and see how that goes. $$anonymous$$eep me posted.
Disabling "Apply Root $$anonymous$$otion" didn´t work. As you can see in the answer below from ibzy, this problem is actually limitation of Unity. You can very easily mimic the situation. Before I succumb to the untidy way of parenting the GameObject, I´d like to know how others solve this issue. Literally every developer got to stumble upon this, yet I don´t see anybody solving this.
Ah, $$anonymous$$isunderstood the question. Cheers
Answer by Ibzy · Jan 20, 2014 at 02:34 PM
Hi George,
I had a similar problem myself, so to get around it I had an empty GameObject as a mounting point, and the animated object as a child set to 0,0,0. When moving the object with transform.position, I would use myGameObject.transform.parent.transform.position - this would move the mounting point while leaving the child at 0,0,0.
Hey Ibzi, thanks for sharing your solution. $$anonymous$$y personal hack is to dynamically create copy of the sprite, and hide the original, so my hierarchy is not messed up. But I will surely keep this in my arsenal of solutions.