Help with changing a spawned actor

I am creating a third person open world game. I have my inventory system all up and running and works great. Its called
BP_Inventory.
Currently I have to spawn it on “begin play” Screenshot below. In that screenshot on the spawn actor node you will see i can control the “Amount of slots” my inventory will have. Currently set to 20 if i press play and open my inventory i will have 20 slots. If i end play change the number to 50 then hit play again then this time i will have 50 slots.

The problem i have is that i want to change this at runtime so my player can start with 20 slots then when they get a level up they will have say 50 slots. Because this actor is spawned on begin play it obviously cant be done through a simple variable change.

I did try to create a function that destroys the actor then spawns it again with the new slot amounts, ive ran this through a “do once” node this function is in screenshot below. This works to a point it deletes the old inventory actor and creates the new one with 50 slots but even with the do once node it doesn’t stop respawning them in the world outliner i watch it got from bp_inventory to bp_inventory1, bp_inventory2 and so on befor i know it im up into the hundreds and because it constantly spawns it again i cant actually pick up items as they are instantly deleted on the respwan. it also sucks up my system resources from constantly removing and replacing the actor.

Is there something i am doing wrong? is there another way to do this? tried so many different ways with varied results but cant seem to get it working i’ve tried to place the actor directly into the world rather than spawn it on begin play but then the inventory doesn’t work at all. any help or ideas greatly appreciated if more info is needed please ask away ill reply as soon as i can.

I don’t think you get the question. You can’t put a spawn actor node on an event tick or it will constantly try to spawn the actor on every tick. Even with a “do once” node it still spawns on every tick as explained and screenshot above. that can also only be done by destroying the actor first which also destroys any current items in the inventory but then it gets stuck in the loop as explained above of constantly destroying and spawning the actor…

If i dont destroy the actor and just use the same actor because it is spawned on “begin play” its variables cant be changed at runtime because it was only executed at “begin play”. if i call it anywhere else tick event or custom events it gets stuck in the above loop no matter what branches or nodes i put before it the “do once” node should stop that happening but it doesn’t.

“You can’t put a spawn actor node”, no you should use a variable …to check and then… the variable affects the player…

where /when are you calling the respawn function? if you have it based on a leveling system like you mention then you would just call the respawn once when the level up occurs. though theres probably other issues at play here as well and there is also probably a better way of handling the addition of inventory slots.

It looks to me like the problem is with the location of your DoOnce node. A function is encapsulated so it runs and then removes itself after completion, so your DoOnce is essentially ignored.

I think if you move the DoOnce outside of the function, and place it just before the call to the function, you’ll get better results.

brilliant thanks for the sensible response worked like a charm as soon as i took the do once out of the function and into the event graph it stopped firing it hundreds of times. I wasn’t aware that they couldn’t be used inside functions thanks so much :slight_smile: