Search Unity

Changing GameObject hierarchy at runtime breaks animator

Discussion in 'Animation' started by MisterMashu, Dec 10, 2018.

  1. MisterMashu

    MisterMashu

    Joined:
    Oct 23, 2012
    Posts:
    4
    Hi everybody,

    In my game, getting hit just means losing a limb, and you can graft new limbs onto your character by collecting them. So my gameObject hierarchy needs to be able to change at runtime. However, I cannot get the Animator to affect my game objects after swapping out limbs for other limbs. I found a function called animator.rebind() which I thought was going to solve my problem but that didn't do anything.

    For some more info: my animations were built by me as a test with the Unity Animation tab. I have my animator controller all set up and everything works perfectly until I swap out a limb, then all animation stops; the character just goes to t-pose and I can still move around, and the animator controller preview even shows the states transitioning correctly, but it just doesn't actually change the rotation values on the arms or anything.

    Does anybody know of a function I can call for it to re-set itself back up again or anything?

    Thanks!
     
  2. GuardHei

    GuardHei

    Joined:
    Feb 10, 2018
    Posts:
    89
    Haven't tried to test it but get an idea. Instead of removing or adding transforms as bones, maybe you can just change the mesh used to render in this case. For a missing limb, maybe you just set an empty mesh or whatever something.