# In Unity - Move a GameObject at Animator State

I want to move one of my GameObject to a different vector 3 position, when animator transit to a new state. How do I do it? Also there shouldn't be any delay.

• Can you show some code of what you've tried? Nov 24, 2016 at 11:38

You Don't need to moving via animating. You can simply make a method that first change the animation state and then move object using Translate method( for instant transition) and MoveTowards or some other methods. Something like this :

Public myMethod (){
animator.set...();
transform.translate...
}


And whenever you call myMethod you have two behaviors together.

• Thanx this gave me a good hint to use a Behaviour, So found a solution, posting below Nov 28, 2016 at 0:43

This is the solution I came up with, In my Animator state I added a behaviour script, that moves the object before the animation starts,

Script is a very simple C# script:

using UnityEngine;
using System.Collections;

public class BehaviorMoveGameObject : StateMachineBehaviour {

public float Position_X;
public float Position_Y;
public float Position_Z;

// OnStateEnter is called when a transition starts and the state machine  starts to evaluate this state
override public void OnStateEnter (Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{

animator.gameObject.transform.position = new Vector3 (Position_X, Position_Y, Position_Z);

}

}