Search Unity

Instantiated object's Animator stops transform.position updates

Discussion in 'Animation' started by SoftwareGeezers, Jan 11, 2015.

  1. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    I have a test character made of sprites animating. I add this
    Code (CSharp):
    1. void Update(){
    2.         transform.position += new Vector3(0.03f,0,0);
    3.     }
    On a character in the level, it moves and animates.

    On a character I instantiate from Resources, it doesn't move; it stands on the spot animating. If I disable the Animator on the instantiated object though, it moves.

    Edit: If I spawn the object at (0,0,0) it works. If I spawn anywhere else, it doesn't move with the Animator active.

    If I spawn the object at (0,0,0) and then immediately move it to a new start location, it also works correctly. Unity 4.5.5p2

    Edit: And now 4.6.1f1

    Seriously, this must be a common issue! Are people not using animations?! Or is everyone spawning at (0,0,0)?
     
    Last edited: Jan 12, 2015
  2. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Normally you shouldn't update your root game object transform in Update function but in OnAnimatorMove().

    http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnAnimatorMove.html

    If your animator has some root motion curve and applyRootMotion is checked then it is expected that anything set in root transform object in the Update function won't move your object.
     
  3. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    Thanks. Is this covered anywhere in a tute? Every example for Mecanim I've found is either talking about importing FBX's with animations or using physics. My game is grid based and very simple, no physics needed. I just lerp from tile to tile. But getting my head around this animation is proving very hard because none of the info matches up with what I'm trying to do. :(

    Edit: Is it safe to chuck all animated graphics into a child object and control the parent for position?
     
    Last edited: Jan 13, 2015
  4. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790

    Hey Geezer - the solution you mentioned was the thought I had when I read your OP. Don't know if it's the right one but that was my first thought to fix the issue you were experiencing.

    Post the solution you end up using.
     
  5. Mecanim-Dev

    Mecanim-Dev

    Joined:
    Nov 26, 2012
    Posts:
    1,675
    Yes that should work.
     
  6. SoftwareGeezers

    SoftwareGeezers

    Joined:
    Jun 22, 2013
    Posts:
    902
    Yes. That actually seems the right thing to do in general regards anything but the simplest Unity GameObjects! ;)