Search Unity

Unable to set position of GameObject with associated animations

Discussion in 'Scripting' started by Karmak, Jan 20, 2014.

  1. Karmak

    Karmak

    Joined:
    Jan 20, 2014
    Posts:
    9
    Hello,

    I am having problem with changing position of GameObject with attached animations via scripting.

    Command:

    Code (csharp):
    1. myGameObject.transform.position = Vector3(0,1,2)
    does not do anything. The myGameObject still resides on its original position, while none of its animations are being played.

    It seems like the existing animations of GameObject override commands for position change, even if these animations are not being currently played.

    Once I delete all existing animations of the GameObject, I can change its position again as expected.

    Do you not feel limited by this?

    It is possible to get around this through hacks - like using duplicate gameObjects stripped of animations, or targeting parenting gameObjects, but it feels like incredibly cumbersome workaround for rather basic functionality.

    What do you think?
    George
     
  2. GarthSmith

    GarthSmith

    Joined:
    Apr 26, 2012
    Posts:
    1,240
    Generally, I'll have a parent GameObject with the animations on a child GameObject. If the animations are controlling the transforms of itself and its children, you shouldn't mess with any of those child transforms. Move the parent instead. Having two different things trying to control the same piece of data is a recipe for chaos.

    Eg: I have a parent character GameObject. There is a child object that handles character animations. I can play a "run" animation on the child object while moving the parent object around.
     
  3. Karmak

    Karmak

    Joined:
    Jan 20, 2014
    Posts:
    9
    Thanks for your insight, Garth.