Search Unity

(2D IK) Animation is broken after moving certains bones

Discussion in '2D' started by lvddiablo, Jan 5, 2022.

  1. lvddiablo

    lvddiablo

    Joined:
    Jan 25, 2021
    Posts:
    3
    Hello, so my question is quite specific and I can't find any answer anywhere else. So for my project, the player can take off parts of his body to progress in each rooms. So he can for example take off his head and throw it or take off his arm to catch things unreachable.
    So here is the problem, whenever the player use that, the bone that is attached to this parts of his body stop working in the anim. The rest still works fine but the head Bone is broken and same for the arm. Just like if they weren't in the anim anymore.

    So i need a way to reattached this bones to the rest of the animation. I hope someone can help me here i am quite desperate lol. Thanks for your time.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,751
    Animations are keyed to bones by name, so you can't remove them and expect them to continue animating.

    Some alternate approaches:

    - use child objects that are NOT animated and parented below those bones and add/remove those, while leaving the bones intact.

    - have completely different models with various combinations of with- and without limbs

    - implement your own animation reconnection scheme perhaps?
     
    lvddiablo and Unrighteouss like this.
  3. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    Using child objects as the above answer suggested is probably easiest way to go about things; however, to elaborate on an "animation reconnection scheme," you can use
    Animator.Rebind()
    to fix your animations after reattaching any bones.

    https://docs.unity3d.com/ScriptReference/Animator.Rebind.html

    You will have to call this method every time a bone is reattached. If you don't have any basic coding experience, you're better off just using child objects that aren't part of the animation.
     
    Kurt-Dekker likes this.
  4. lvddiablo

    lvddiablo

    Joined:
    Jan 25, 2021
    Posts:
    3

    Thanks for your quick answer ! I was thinking about your first solution and that's what i thought was the better or at least the easiest. I'll will try and get back to you guys, thanks a lot!
     
    Unrighteouss likes this.
  5. lvddiablo

    lvddiablo

    Joined:
    Jan 25, 2021
    Posts:
    3
    Oh thanks for that i'll see if i can use that in my scripts ! Thank you for you answer !
     
    Unrighteouss likes this.