Change an Actor Class' Variable before spawning

I have an inventory system that allows you to drop items back into the game when you remove them from your inventory and I need a way to open the Actor Class before spawning (dropping) it into the world.
Example: I have a box of 9mm rounds that is a qty of 25 rounds by default, I pick two of them up and shoot 10 rounds leaving 40 rounds in my inventory. I want to drop this as a 40 round box of ammo. I need a way to break open the Actor Class before I send it to Spawn Actor so I can change the default of that actor to 40 rounds. I could cast to it but I have 10 ammo types (will be more in the future) so it may be rather lengthy to do… Is there an easy (or I guess hard) solution for this?

I figured this one out after a few hours of banging my head against the wall… I have to specify which actor class I want to modify, it will not allow me to put an actor class variable and change it in game. Since I have numerous ammo types I had to do a branch system to look for the Item ID that I am dropping and it will spawn an that actor. I used the return value to modify the struct inside my inventory Item to set a quantity and all the other things needed so if I picked it back up it would recognize it and add it back.

Hi, I know this has been over a year but I have the same problem. How did you get the blue struct pin on the actor SET? On mine I promote the spawned actor to a variable but it doesn’t have that blue struct pin to plug the structure into. Could you tell me how you got that blue struct pin on that set node. Thanks

Figured it out

I know this was answered already but anyone trying to modify variables prior to spawning an object should look into the Expose on Spawn boolean rather than create separate blueprints just to change 1 variable. It is found in a variable’s Details panel.

283462-exposeonspawn.png

2 Likes

OMG, that’s what that boolean does. lol
Thank you :slight_smile: