Setting up a system that only spawns projectiles, VFX, and plays animations specific to the weapon that is currently equipped.


So I am currently developing a fan remake of a classic shooter, Painkiller, made by People Can Fly in 2004. So I may have more questions in the future if I can’t find any solutions beforehand.

So far, I have successfully made an array system that allows me to switch between the different weapons I have set up in the array as shown below.

However, when I start the level and fire the weapons, it spawns all the projectiles from all weapons (Shotgun pellets, Rockets, Minigun Bullets, etc) instead of only spawning the projectiles and only playing the animations of the currently equipped weapon.

How would I set up or link to the array (since all of my weapon fire animations, sounds, and projectiles are set up in their own individual weapon component BP classes) a system that will only play and spawn attributes of the currently equipped weapon?

Thank you for your help!!

Can you show the logic used to fire the weapon?

This sounds like it would fit in a Serious Sam game, not a Painkiller game :smiley:

1 Like

Here is the logic for the Shotgun. One image contains the logic used for playing the animation, sounds, and attaching a muzzle flash. The other image contains the logic used to spawn the projectiles when fired. All other weapons have structures just like this in their own component BPs. I’m just unsure what other logic to put in so that it doesn’t play all of these at once and only runs whatever component that is linked to the currently visible weapon.

normally, the weapon knows what projectile/vfx it should spawn, and spawns it. i have no idea how you’d get to this point

When you spawn with Begin Play, are all your weapon blueprints also spawned? I can only imagine that all weapons are firing because they are instanced and are all triggered with the same enhanced input action.

Yeah, all the weapon components are linked to the same binds - LMB for primary fire and RMB for secondary fire. So I was wondering if there was some function or system I could setup to prevent all weapon anims and projectiles to play except for the currently equipped weapon. I suppose anything similar to this equip weapon function I have in the First Person BP that only toggles visibility of the currently equipped weapon may work?

so… you literally are tying into the input mechanism for every single weapon, and firing every single weapon on the same command.

… you probably should have a function inside each weapon that handles firing, and then call the current weapon’s firing function on the input… rather than trapping the input in every weapon.

or just have it so only one weapon exists at a time, i guess

1 Like

I figured it out! I finally found a tutorial series made by a guy named Ryan Laley on YouTube. In his weapon switching video, it covers everything necessary to switch between every weapon in your inventory and also display the correct animations and projectiles for what is currently equipped.

I dumped the weapon component classes and made new BPs. I made a parent class and have all the different weapons made as child classes from that parent BP.

This allows that array system from before to properly work this time. So if it helps you guys too, take a look at Ryan’s tutorials as I’ve found they cover a lot of specific topics! Also thank you guys for your help!