Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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 :)

Thank you very much in advance!!

Product Version: UE 4.18
more ▼

asked Mar 28 '18 at 01:17 PM in Blueprint Scripting

avatar image

151 2 7 23

avatar image eagletree Mar 28 '18 at 05:15 PM

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.

avatar image apokalypto Mar 29 '18 at 11:02 AM

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!!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Mar 29 '18 at 04:25 AM

avatar image

Nebula Games Inc
5.4k 28 9 15

avatar image apokalypto Mar 29 '18 at 11:04 AM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question