Need guidance on weapon loadout array setup

Hello everyone!

I need some help dealing with instances of spawned actors. I have set up a Default Loadout Array which does a For Loop and adds items to my Current Loadout Array when my character spawns, similar to the way ShooterGame does it. Once it has added all weapons to the array it sets my currentweaponIdx to be 0, which tells my Spawn Actor Node what class to spawn from the array. This part all works.

I can switch weapons simply by adding or subtracting from my index number, perfect!

Now here is where it all starts to go wrong. My only option so far when switching weapons to is to destroy the previous actor. When I scroll back to the weapon, it spawns a new instance. A new instance every time i change weapons meaning I have none of the changed variables from the previous instance. ShooterGame handles this part differently, each time you change weapons it switches back to the same instance and I have no idea how they did it. I have gone over the code numerous times but my understanding of C++ is limited. This is where I need some guidance, arrays are very new to me. What are my other options?

Rather than destroying it, why not just hide it and move it out of the way? Seems like the simplest way to achieve the desired effect. Then instead of spawning the actor each time you are just checking the value of what should be equipped and making it visible and attached at the right socket.

I built a rather similar system for my FPS game and I did what ZoltanJr described. I’m showing the current equiped weapon and hiding all of the others.

Hah, that is the solution I came up with very shortly after posting this, so I can tell you it does work, thanks!

I change the Current Loadout array to be Actors then I moved it and the Add Unique to be after the spawning, and then Set Actor Hidden In Game. On completion I Un-hide the weapon in slot one, and switching takes my current weapon and hides it then shows the next.

Now I just need to deal with the idle sounds because they still play even when the actor is hidden. I also thought of not hiding them and instead attaching them to another socket on the back or side for visual effect. I’m going to expand this to be more than weapons but also grenades, packs and deployables. This will require me to make an Struct of Class Structs I believe

Here is the important part I missed yesterday in the ShootGame code. The Equipping/Unequipping part is built into the weapons themselves, the character just triggers the event. When the character spawns the actor, Event Begin Play on the actor detaches the mesh and set actor hidden, this is the reverse of how I have done it. Then they Re-Equip the weapon which reattaches the mesh to the owner and sets it up for use.

This gives me lots of ideas :slight_smile: