How to reset object and all its components, scripts, etc, to start state?

I have a few weapons, and when I fire one then quickly press the change weapon button mid-firing to select a new weapon (which sets the current weapon object to SetActive = false and the new weapon to SetActive = true), the current weapon seems to store all the animation positions, the ejected shell state, any timers in the scripts attached to it, and whatever else, such that if I cycle round to it again (setting it to SetActive = true again), it appears stuck half way through the previous reload animation and the shells suddenly finish ejecting and so on. And even if I press the fire button again, thinking this might at least go through the sequence and get the weapon back to its default state, it does the fire animation and stuf over the mid-reload animation so everything it messed up (the shotgun fires, with the kickback, but looking like it’s bent in half and open so as to eject the shells).

What I want, whenever I cycle to a new weapon and then back again, is for each weapon to reset everything to do with it to the state it was in when it was first created in the game (but not by destroying and then instantiating objects as this is going to cause too many issue with the way my game is setup).

How do I do this properly? Is there a simple way I can do something like “Activate this weapon again but reset it as though it was being created/activated for the first time, so the animations are back to starting state and any scripts are running from their starting states and so on”?

Or am I just missing something here and there’s possibly something I’m doing wrong that’s creating an issue that could be resolved relatively easily some other way?

Good day.

I know there is this:

But an easy way to do it is to remove all its components and attach them again, for example a script called “BestScript”

 Destroy (Object.GetComponent<BestScript>();

and add it

The only things that are not involved are relative to transform compoennt, which you wil need to set again (if needed) position, rottaion, scale and chiltparent relations.



Well, you have the

which allows you to do what you want when the object becomes active. If you SetActive(false) it, and then (true) it will run the method again.

So if you configure your Start() and/or Awake() methods in OnEnable(), it will set all initial values all time becomes active.

Or directly, create a Reset() method, where you just Instantiate one copy of it, and destroy itself.

Bye!