Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Question Reload animations with multiple instantiated weapons

Discussion in 'Animation' started by Leobg, Oct 4, 2022.

  1. Leobg

    Leobg

    Joined:
    Oct 30, 2019
    Posts:
    2
    Hi everyone!

    I am doing this post because I encounter a problem on how to animate several instantiated weapons while keeping the same base.
    I develop an FPS, so I have a prefab with FPS hands and each weapon is instantiated when used.
    As I have to animate the hands + each weapon, I don’t see what would be the best solution to do something efficient with, preferably, a single AnimatorController capable of managing all reload animations, even if the weapons are instantiated?

    I don’t know how else to do that other than by creating a prefab including the hands + the weapon, for each weapon but it’s clearly not the best solution :(

    Would it be better for me to set them in the prefab instead? And to activate only the selected weapon? Even though there are a lot of guns? I think it's a good solution but how can I manage all animations clips for each reload animation ?

    Thank you very much in advance for your help!
     
  2. Unrighteouss

    Unrighteouss

    Joined:
    Apr 24, 2018
    Posts:
    599
    I think making them all part of the prefab and enabling/disabling the guns you need is a good option. I'm no expert on optimization, but even dozens of disabled guns should be fine.

    If you want to instantiate the guns, know that instantiated objects aren't properly hooked up to their animations. Unity optimizes animations at runtime, and any missing objects won't be included in the calculations. You can use
    Animator.Rebind()
    each time you instantiate a weapon to make its animations work: https://docs.unity3d.com/ScriptReference/Animator.Rebind.html