Remove Item from level w/o destroying it?

Which blueprint holds the array?

I have a pickupitem (actor-blueprint). On pickup I store the pickedup-item in the inventory-array. Then I destroy the actor to remove it from the level. BUT, destroying the actor also destroys it in the array.

I was thinking about just moving the item outside of the level boundaries. But that is kinda a nasty workaround. Especially if the item is money or some ‘stackable-item’. Just making the actor invisible may still trigger certain events so that is not good either.

How do I solve this… I don’t like to create another item-blueprint dynamically and assign that one to the inventory. I know it can be done with just one blueprint.

How did other people solve this?
Base-item blueprint on-pickup code:

Note: The InventoryItems-array is stored in MyCharacter. So the array itself is never deleted.

MyCharacter

Well it doesn’t destroys the actor inside of the array… but your array only holds a reference to the actor and not the actor itself.

The best solution I found so far was hiding the actor. This is not removing the collision so you will have to do that manually if it has any but it will remove any visuals.

If you are not depended on functionality inside of the actor but mainly on variables I would suggest using a struct to store all those variables and just work with that from then on because a struct is not reliant on the actor so you can use it just like any other variable after the actor was destroyed.

If you definitely need it but only at very specific moments think about collecting the variables in a struct together with the class of the actor and just spawn it new when you need it with all variables set like they were when you interacted with it the first time.

I know that’s still not a perfect solution but I still hope it helps.

Cheers.

That’s no good. What if the item can be upgraded or changed? Do I then have to add some complicated string like: “chair;blue;level10;texture;qualityx;etc”? And then convert that to the real item/info that I want afterwards? That only works for extremely simple items that can never be modified.

Yes the inventory-variable only contains a reference. I suppose that you can’t put an actor (or any blueprint) inside of a variable anyway. Only references.

Well I could put all the item’s variables into a struct, and then put that struct into the item-blueprint. Then when I assign the struct (I suppose that they are passed by value instead) from the actor to the inventory, it should then be a copy. If not I could duplicate the struct I guess.

BUT, if I want to drop the item again, I have to create a new actor based on that struct… It’s indeed not a perfect solution but it will work.

Is there really no option to remove an actor from the level so that it is no longer responds to it’s event-graph, is not rendered and has no collision? Because making it invisible, setting it’s collision to none and moving it far away from the level may still trigger code in it’s event graph (or for it’s child’s eventgraph). I would have to add branches everywhere… Also far from perfect.

Okay, maybe instead of adding the actual blueprint to the array, just add a string to an array. Or a boolean or something. If you make an inventory system you could just add a string with the name of the item (for example ‘Knife’) and in the character blueprint just check through the array to find what items are in the player’s inventory.

In the end I went with this

Structs were somewhat problematic because I had to break them EVERYWHERE. Annoying beyond belief. I use the variable PickedUp? in the Graph section of items to prevent them from responding to events.

Alright. I hope this solves it for you and if I should ever find a better solution to do this in blueprint and I still remember this post I will certainly give you a heads up :wink:

Thanks for sharing this as well. It’ll be easier for people who might take a look at this in the future. Just for clarity would you mind accepting an answer or just answering this question yourself with what you did and then accept it? Unless of course you want to wait for more answers but if you’re moving on from this problem it’d help signalizing others that this is solved and doesn’t need more attention.

Thanks and have a great day! :slight_smile:

Structs were somewhat problematic because I had to break them EVERYWHERE. Annoying beyond belief.

The below is a function of BP_BaseItem (the topmost-parent-blueprint of your items) and basically you call this whenever you want to ‘remove’ it from the level without destroying it. Technically you don’t need to change the location of the item because you already set it to invisible + no collision and all events are disabled. But, I included it anyway and also stored the pickup location in case I ever need to restore the item to it’s original location.
I use the variable PickedUp? in the Graph section of (child)items to prevent them from responding to events by using this as the branch condition.

The solution is not perfect, but still the best I know of so far.

I hope that Epic will give us some method in the future to remove items from play (or to a dummy level) without destroying them.