Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Instantiating prefab with animator component

Discussion in 'Prefabs' started by twocool, Mar 4, 2020.

  1. twocool

    twocool

    Joined:
    Jan 16, 2014
    Posts:
    16
    Good day!

    I created a GameObject, added the Animator component to it and then made a prefab of it. Animator has 5 states: Idle, Moving, Attacking, Hurt, and Dying. When I run the game, I am of course Instantiating it so it shows up as GameObject(Clone) in the Hierarchy. When trying the Moving state, it doesn't look as though that the Animator component was instantiated with the GameObject prefab.

    Any help or resources would be greatly appreciated.

    Thank you all!
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi @twocool,

    You said "It doesn't looks as though...". So, does the object have an animator or not? This should be trivial to verify if you just select the object in Editor and see if there's that component. I doubt the states have anything to do with that error. Maybe something is not assigned correctly, some parameters are set wrong or something else fails... Hard to guess. But verify first that you do have the Animator component, and that the Controller, Avatar etc. are set correctly. Also, have you verified that the state changes etc. you're trying to perform are actually passed to that instance of the object?
     
  3. twocool

    twocool

    Joined:
    Jan 16, 2014
    Posts:
    16
    Sorry for the confusion with the GameObject having the Animator component. Yes, the states were working before I made the GameObject a prefab and does work if it's in the hierarchy. If it's not in the hierarchy and I instantiate it, the states no longer work so I'm thinking the Animator component isn't being passed with the Cloned GameObject.