Save actor data when destroyed and spawn this specific actor

Hi all,

Currently I have an inventory and weapons that can be used. For equipping weapon functionality I use “Spawn Actor from Class” node. It spawn a actor from my Parent Weapon class. If I unequip/move that item into my inventory the actor gets destroyed. So when equipping the same weapon it spawn a fresh actor from that class:
For example equipping BP_AssaultRifle then unequipping and equipping it again it will spawn BP_AssaultRifle_1 then BP_AssaultRifle_2 and etc…

My problem is that I want to be able to save the current item status when unequipping it and spawn it with the same status when equipping it again but I’m not sure which unreal functionality I should use for that purpose.

So I’ve been able to do something similar but without destroying the spawned actors. Also I’m thinking of other work around like keeping the ammo count in the character.

Edit: Thoughts on the workaround - Current ammo should be stored somewhere as we don’t want the owner to set it to 30 every time he unequips and equips the weapon. So the work around will work only for the Max ammo…

Edit 2: My Inventory items are based on Structure that includes ID, Name, Type and etc. One of these structure variables is my ParentWeapon where I can select the Weapon Class. I have components that remove and add items to a array of elements from my structures type.

Please share your ideas and advises with me :slight_smile:

Thank you very much in advance!!

I’m not sure what your inventory looks like, but for mine, I keep the specific instance of the weapon rather than a reference to the generic blueprint by keeping extra information (i.e., I can respawn the specific instance later just like it was). Within that instance data is the current magazine count. I assume that the player can pick up multiple copies of the same weapon and that they need to be discrete instances once picked up. Ammo count and customizations are then dragged into the instances inventory entry on despawn. When the player selects that instance from inventory, what is respawned has the customizations and ammo from the weapon put away earlier. The negative of this is that inventory items that aren’t weapons, carry along unused empty values that the weapon needs. It was my quick and dirty way to do this though it would be considered somewhat of a kludge.

You could just have a function in the player for each type of inventory item class that has the same variables you need to store (weapons, power ups, etc) and call that function which then saves a class specific struct of variables. Then when you spawn the next actor use the struct variables to set the new actor parameters.

Thank you for your advise eagletree! I’m going to give it a try and see what comes up. I’ll keep you updated on the current status. Also I’ll add more information about my Inventory Item in the main post. Thanks again!!

Thanks Nebula Games Inc! I’m going to try setting up such functionality for the Weapon Class. I’ll keep you updated :slight_smile: Thanks again!!