# How can i keep a variable referencing an actor after destroy?

**URL:** <https://forums.unrealengine.com/t/how-can-i-keep-a-variable-referencing-an-actor-after-destroy/441228>\
**Category:** Blueprint\
**Tags:** Destroy-Actor, unreal-engine, UE4, question, Blueprint\
**Created:** [January 13, 2019, 6:09pm UTC](https://forums.unrealengine.com/t/how-can-i-keep-a-variable-referencing-an-actor-after-destroy/441228 "2019-01-13T18:09:15Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrizen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@andrizen](https://forums.unrealengine.com/u/andrizen)\
**Post date:** [January 13, 2019, 6:09pm UTC](https://forums.unrealengine.com/t/how-can-i-keep-a-variable-referencing-an-actor-after-destroy/441228/1 "2019-01-13T18:09:15Z")

</div>

So i am working on a inventory system.  
The code i have set the “Pickable” item on the ground to an element array of “Pickable” class .  
and then i destroy the object in the ground.  
after destroying the object i lost the reference in the array element…

That array is my inventory.  
How can i keep the object that i grab in the array but destroy it in the game world?

---

<div class="post-metadata">

**Author:** ![DonleyStudiosInc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DonleyStudiosInc](https://forums.unrealengine.com/u/DonleyStudiosInc)\
**Post date:** [January 13, 2019, 6:21pm UTC](https://forums.unrealengine.com/t/how-can-i-keep-a-variable-referencing-an-actor-after-destroy/441228/2 "2019-01-13T18:21:58Z")

</div>

Can I see the code you have for picking it up and destroying it

---

<div class="post-metadata">

**Author:** ![andrizen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@andrizen](https://forums.unrealengine.com/u/andrizen)\
**Post date:** [January 13, 2019, 6:33pm UTC](https://forums.unrealengine.com/t/how-can-i-keep-a-variable-referencing-an-actor-after-destroy/441228/3 "2019-01-13T18:33:01Z")

</div>

![265271-error1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/6/2/a6296f20720943e31a984c06684afed371bbab11.png)

 ![265272-error2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/3/8/23810e6f6085f693297b103e2660426c2769a825.png)

---

<div class="post-metadata">

**Author:** ![Evigmae](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/evigmae/32/1187349_2.png) [@Evigmae](https://forums.unrealengine.com/u/Evigmae)\
**Post date:** [January 13, 2019, 6:38pm UTC](https://forums.unrealengine.com/t/how-can-i-keep-a-variable-referencing-an-actor-after-destroy/441228/4 "2019-01-13T18:38:19Z")

</div>

Well, you’re getting it wrong.

The reference in the array is of the actual object, when the object is destroyed the array now has a reference to nothing.

What you need instead is an array of a struct to copy over all the relevant data from the object you just picked.  
Like, object type, stats, etc. Whatever you need.

But you absolutely can’t access an object after it’s been erased from existence.

---

<div class="post-metadata">

**Author:** ![andrizen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@andrizen](https://forums.unrealengine.com/u/andrizen)\
**Post date:** [January 13, 2019, 6:44pm UTC](https://forums.unrealengine.com/t/how-can-i-keep-a-variable-referencing-an-actor-after-destroy/441228/5 "2019-01-13T18:44:53Z")

</div>

So in that case i can’t use the functions i have on the Item BP, right?  
Like if i do that, imagine that when i touch the E Button i want to run some piece of code in Item BP, like Eat() , for example.  
All codes should be moved to ThirdPerson Character BP?

---

<div class="post-metadata">

**Author:** ![DonleyStudiosInc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DonleyStudiosInc](https://forums.unrealengine.com/u/DonleyStudiosInc)\
**Post date:** [January 13, 2019, 7:19pm UTC](https://forums.unrealengine.com/t/how-can-i-keep-a-variable-referencing-an-actor-after-destroy/441228/6 "2019-01-13T19:19:20Z")

</div>

it does destroy just doesn’t go into inventory correct?

---

<div class="post-metadata">

**Author:** ![andrizen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@andrizen](https://forums.unrealengine.com/u/andrizen)\
**Post date:** [January 13, 2019, 7:34pm UTC](https://forums.unrealengine.com/t/how-can-i-keep-a-variable-referencing-an-actor-after-destroy/441228/7 "2019-01-13T19:34:01Z")

</div>

yes thats true

---

<div class="post-metadata">

**Author:** ![DonleyStudiosInc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DonleyStudiosInc](https://forums.unrealengine.com/u/DonleyStudiosInc)\
**Post date:** [January 13, 2019, 7:44pm UTC](https://forums.unrealengine.com/t/how-can-i-keep-a-variable-referencing-an-actor-after-destroy/441228/8 "2019-01-13T19:44:29Z")

</div>

right before you destroy it add it to your inventory and see if that takes care of it

---

<div class="post-metadata">

**Author:** ![andrizen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@andrizen](https://forums.unrealengine.com/u/andrizen)\
**Post date:** [January 13, 2019, 7:48pm UTC](https://forums.unrealengine.com/t/how-can-i-keep-a-variable-referencing-an-actor-after-destroy/441228/9 "2019-01-13T19:48:29Z")

</div>

it is already done in the player BP , when i set elem array

---

<div class="post-metadata">

**Author:** ![DonleyStudiosInc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DonleyStudiosInc](https://forums.unrealengine.com/u/DonleyStudiosInc)\
**Post date:** [January 13, 2019, 7:56pm UTC](https://forums.unrealengine.com/t/how-can-i-keep-a-variable-referencing-an-actor-after-destroy/441228/10 "2019-01-13T19:56:06Z")

</div>

which one is adding it can i see that code

---

<div class="post-metadata">

**Author:** ![andrizen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@andrizen](https://forums.unrealengine.com/u/andrizen)\
**Post date:** [January 13, 2019, 8:04pm UTC](https://forums.unrealengine.com/t/how-can-i-keep-a-variable-referencing-an-actor-after-destroy/441228/11 "2019-01-13T20:04:06Z")

</div>

![265274-setarr.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/6/4/564a9c65981a41bc070af291029910e012f129ac.png)

---

<div class="post-metadata">

**Author:** ![Aahan1895](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aahan1895](https://forums.unrealengine.com/u/Aahan1895)\
**Post date:** [December 26, 2024, 2:42pm UTC](https://forums.unrealengine.com/t/how-can-i-keep-a-variable-referencing-an-actor-after-destroy/441228/12 "2024-12-26T14:42:42Z")

</div>

Thanks a Ton. ive been trying to wrap my head around it for quit some time now
