Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    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:
    440
    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
     
unityunity