# Pass copy instead of reference

**URL:** <https://forums.unrealengine.com/t/pass-copy-instead-of-reference/421991>\
**Category:** Editor Scripting\
**Tags:** inventory, collectables, unreal-engine, spawning-actors, Blueprint, question\
**Created:** [April 6, 2018, 3:05pm UTC](https://forums.unrealengine.com/t/pass-copy-instead-of-reference/421991 "2018-04-06T15:05:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Natural\_Games](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Natural\_Games](https://forums.unrealengine.com/u/Natural_Games)\
**Post date:** [April 6, 2018, 3:05pm UTC](https://forums.unrealengine.com/t/pass-copy-instead-of-reference/421991/1 "2018-04-06T15:05:08Z")

</div>

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](http://www.tomlooman.com/tutorial-basic-inventory-system-in-blueprint/) 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.

---

<div class="post-metadata">

**Author:** ![Natural\_Games](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Natural\_Games](https://forums.unrealengine.com/u/Natural_Games)\
**Post date:** [April 6, 2018, 4:05pm UTC](https://forums.unrealengine.com/t/pass-copy-instead-of-reference/421991/2 "2018-04-06T16:05:50Z")

</div>

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.
