Pass copy instead of reference
So I store my entire inventory in an array of a custom type "Collectibles" which inherits stuff like name, amount etc. to other item types like weapons. I just would like to add i.e. a weapon from the world to the player's inventory array and then remove it from the world with the destroy actor function. Unfortunately, if I add an item to the array, only the reference gets added and as soon as I call "destroy actor", the items in the inventory remain, but the properties are all wiped out. Is there a way to pass a spawned object as copy into a blueprint function?
Another approach would be to write this in C++ and pass it as copy there or I could also construct a new object of that type and set all the values, but I feel like that's not good for the performance. I also read about an inventory system where you create an actor that handles the pickup and drop.
I'm not sure what I should do. I hope someone can tell me which way is better. I don't have a problem using C++ aswell, but I try to avoid it since Blueprints are easy to use (normally).
Thanks a lot in advance.
Okay, so I found out a solution by myself and want to share it for people who need help aswell. To understand this solution, you might need to know my object hierarchy first, so:
Superclass (top parent): CollectiblesInterface (actor component) -> inherits to WeaponBase (actor component) -> inherits to test_weapon1 (actor component)
This makes sure that any item has the variables "weight", "rarity", "name" and "icon". These are the things I need to store in my inventory. I didn't think right about it, because actually you don't need to have the objects in your inventory, you just need the relative data. So in my case I created a new struct type called CollectibleStruct where I added the variables that every collectible has. Now if the player collects i.e. a weapon, all of the weapon's values get into the inventory, not the weapon itself.
answered Apr 06 '18 at 04:05 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here