Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Animation of items created at runtime

Discussion in 'Animation' started by Hooni_01, May 2, 2024.

  1. Hooni_01


    Feb 12, 2023
    I encountered the following problems while creating new items.

    Once the player selects an item in the quick slot, create a prefab for that item under the player's right hand bone.
    And the player plays the animation clip including the bone of the item through the player animator.
    Then the animator is not aware of those item bones, so I have to call Animator.Rebind().
    But I don't want the animator to reset with existing animations playing.
    It is also difficult to place items under the player from the beginning.
    Because there are so many items available in this game.

    How do other games deal with the issue?
    Or am I approaching the issue in the wrong way?

    Please advise me.
  2. ArachnidAnimal


    Mar 3, 2015
    For a simple solution: if you want the player to hold an item, you can just parent the item to some bone on the hand. The item will move with the hand. The animator of the player should not need to be aware of the item that is being held, and it shouldn't affect the animator.
    Or you could have a script on the item which constantly sets its position and rotation to some bone.
    Code (csharp):
    2. void Update()
    3. {
    4.   transform.position = bone.transform.position;
    5.   transform.rotation = bone.transform.rotation;
    6. }
    Also, a "Prefab" is something that exists in the assets folder. Once it's in the scene, it's no longer a prefab.
  3. Hooni_01


    Feb 12, 2023
    Oh, thank you.
    I think my question was ambiguous.
    What I wanted to ask is the part related to Rebind.

    Let's say there is a motion in which the player throws the dagger in the air and grabs it.
    I want to control both the player and the dagger with one unified animation.
    However, since the dagger was created at runtime, the bone of the dagger will not be affected by the Animator.
    Is there a way to solve this situation without Animator.Rebind?

    Or should I create separate animations for the player and the dagger and sync them?