Spawning a Weapon prefab without the actual functionality

Hey guys,
so first off, I’m trying to make a 2D Top-Down Shooter. I got the basic movement and weapon system going and would now like to drop weapons to the ground and pick them up.

Let’s say I have a Pistol Prefab. This Prefab has a Pistol Handler-Script which takes a ScriptableObject with the Stats for the gun. The Pistol Handler Script inherits from a Weapon Handler Script, which implements Aiming at the Mouse Position. The Shooting is implemented in specialized scripts (like the Pistol Handler) because every weapon shoots different. Below is the Pistol Handler Script.


If I assign the Pistol Prefab to the Player, it’s all working fine. But if I spawn it into the world, the item spawns with the Pistol Handler Script, which means that the spawned Pistol also aims at Mouse-Position and tries to shoot. Now say I want to spawn a Pistol to the ground: Is it a good Practice to create a “Spawned Item”- Class in which I instantiate the Pistol and disable the Script attached to it? And when the Player picks it up, it is enabled again? Or should I completely re-new the system because there isn’t a good way to do it?

Thanks in advance for your answers.

i think i understand the issue. You could probably do the Spawned Item method you mentioned, but i think (and i could be very wrong) having a “collectible only” prefab may make things simpler. So when you drop the weapon, it spawns a collectible prefab version of it that only has the sprite, collider, and logic to be picked up. When picked up, it enabled or spawns, etc the actual prefab that has actions/functions.

I just worry about the disabling script part you mention in case of errors. Maybe it doesnt disable/enable the script on the weapon after picking up/dropping them 3+ or some random amount of times. Long story short, i fear there may be more bugs with that system than the other i mentioned.

Hey,
thanks for your reply!! Yeah, the bugs are something that came to my mind too when thinking about enabling/disabling scripts. So your approach is for sure more bug safe.
So that’s fore sure something I will consider.
But I’m still very open for more suggestions.