Search Unity

Instantiating prefab animator stays always in idle

Discussion in 'Animation' started by astingengo, Jun 11, 2022.

  1. astingengo

    astingengo

    Joined:
    Apr 28, 2022
    Posts:
    25
    I'm trying to instantiate a gameobject that has attached an animator to it [it is a character, based on user selection].
    The problem I'm having is that the character will not move [animation, it will move on the terrain but not the animation]

    It is staying always in idle mode
    What I'm doing wrong or what should I do to make it work?

    L.E: the code that I'm using is from starter assets and I'm instantiating inside geometry object

    Code for instaintiate
    Code (CSharp):
    1.  
    2. character = Instantiate(CharacterName, new Vector3(0, 0, 0), Quaternion.identity);
    3. character.transform.SetParent(Geometry.transform);
    4.  
    where CharacterName is a prefab and Geometry is the Geometry object from PlayerArmature
     
    Last edited: Jun 11, 2022
  2. astingengo

    astingengo

    Joined:
    Apr 28, 2022
    Posts:
    25
    I founded the problem but I can't solve it via code.
    So ... if from PlayerArmature I disable Animator component and then enable it it will work. But if I'm doing that form the code [e.g.: inside Start method] it is not working

    Why?
     
  3. astingengo

    astingengo

    Joined:
    Apr 28, 2022
    Posts:
    25
    No one no ideas?
    So if I'm doing:
    Code (CSharp):
    1. PlayerArmature.GetComponent<Animator>().enabled = false;
    2. PlayerArmature.GetComponent<Animator>().enabled = true;
    it is not working ... but if manually I'm disabling and activating it will do the trick
     
  4. astingengo

    astingengo

    Joined:
    Apr 28, 2022
    Posts:
    25
    No ideas? Can I give more information [what exactly]?
     
  5. astingengo

    astingengo

    Joined:
    Apr 28, 2022
    Posts:
    25
    I'm still hoping here as unfortunatelly I didn't founded a solution.
    So what I'm having is unity asset starter with custom characters attached to the geometry game object from playerarmature.

    The problem is that I instantiate the character from geometry game object [from unity starter assets] and the animation is not working in that case. If I manually, while the play button is on, I deactivate and reactivate the animator from playerarmature object the animation with start to work correctly.
    If doing that from code, nothing happens
     
  6. astingengo

    astingengo

    Joined:
    Apr 28, 2022
    Posts:
    25
    Wow ... finally ... problem solved ... if someone else will have the same problem you need to rebind the animator
    In my case
    Code (CSharp):
    1. PlayerArmature.GetComponent<Animator>().Rebind();