Search Unity

Animator in prefab does not get initialized

Discussion in 'Prefabs' started by vuribe_p, Jul 23, 2019.

  1. vuribe_p

    vuribe_p

    Joined:
    Dec 16, 2018
    Posts:
    2
    Hi,

    I have units as prefabs, each with an animator and an animator controller.
    The controller has 4 states, and 3 layers changing the animations of each state.
    When I spawn a unit, I get the warning "Animator is not playing an AnimatorController". The trouble is that I try to change the weight of the current layer, but the layerCount property give me 0 and GetLayerIndex(name) gives me -1.

    I gather something is wrong with the prefab or with the controller.
    So far I tried to create an empty controller: same result and to move my prefab from an assetBundle to the Resources folder: same result.

    I also tried to do a SetActive on the gameObject once instanciated, do a anim.Play and so on, without luck.

    Do you have any idea ?

    Thank you

    Edit 1:
    To explain a little bit how is the process:
    step 1: the player choose where to spawn a unit
    step 2: I instantiate the model from asset bundle (working fine)
    step 3: I check if the unit has an equipment and, if so, step 4
    step 4: I instantiate the model for the equipment from asset bundle (working fine) and change the layer from the animator of the unit to match the equipment (barehanded, one handed, two handed, bow...)

    So step 4 is not working, I have a few warnings, all linked, when I try to change the layer weight saying "animator not playing an animator controller" (getting layer index, changing weight and so on).

    Edit 2:
    I'm also looking at Rebind() but with no luck. I will try to rebuild the prefab from scratch, put it in the resources and see if the animator works...
     
    Last edited: Jul 24, 2019
  2. vuribe_p

    vuribe_p

    Joined:
    Dec 16, 2018
    Posts:
    2
    Hi,

    I found a way to make it work, I put a boolean and in LateUpdate I check if the boolean is at false and the animator component is activeAndEnabled, then I do whatever I need with the animator and put the boolean to true.
    It works although I don't get why the animator component takes so long to active...

    I will continue with this for now but if anybody has a clue, please do tell me!
     
  3. vaki26

    vaki26

    Joined:
    Jan 23, 2015
    Posts:
    22
    Have you got resolution on this, I am having the same issue. Could I see how you are checking and what you are doing to get the animator active ?