# Adding and removing actors from an Array?

**URL:** <https://forums.unrealengine.com/t/adding-and-removing-actors-from-an-array/484587>\
**Category:** Editor Scripting\
**Tags:** arrays, unreal-engine, Array, question\
**Created:** [June 8, 2021, 11:27am UTC](https://forums.unrealengine.com/t/adding-and-removing-actors-from-an-array/484587 "2021-06-08T11:27:54Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Todeswalzer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Todeswalzer](https://forums.unrealengine.com/u/Todeswalzer)\
**Post date:** [June 8, 2021, 11:27am UTC](https://forums.unrealengine.com/t/adding-and-removing-actors-from-an-array/484587/1 "2021-06-08T11:27:54Z")

</div>

I’m relatively new to using UE4 and I’m trying to recreate a puzzle game I started making years ago on an old, outdated program. I have, after much trial and error, managed to get most of my core ideas down and sorted, what I am struggling with, however, is arrays.

 ![340990-conphewz2021.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/1/e/01ef9f984f4ebf6c908690e46f83ea91b0e6823d.jpeg)

What I have here, is when the player passes over the striped blocks, they explode. What I need is a way to check to see if all the blocks have been destroyed before allowing the player to move to the next level (and change a red light to green). As I understand it, the best way to do this is with an array, but after reading lots of articles and tutorial videos, I STILL have no idea how to do it. Can anyone offer any advice?

Much appreciated.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [June 8, 2021, 2:23pm UTC](https://forums.unrealengine.com/t/adding-and-removing-actors-from-an-array/484587/2 "2021-06-08T14:23:53Z")

</div>

There are many ways to approach it. And arrays help but are not technically necessary here.

Consider the following:

 ![341008-screenshot-1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/5/a/95a06a7dad954fedd08340492b70c403a9bf6f38.png)

- at Begin Play we count the blocks and store the amount
- when the player runs into a block, it gets destroyed and we count down
- when the Block Count is low enough, the game is over

[![Image from Gyazo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/5/1/3517e8ae7b639b82f970c91df78051ff906f6657.gif)](https://gyazo.com/fe3db4f5d505b2653d5e239fd87a1308)

---

<div class="post-metadata">

**Author:** ![Todeswalzer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Todeswalzer](https://forums.unrealengine.com/u/Todeswalzer)\
**Post date:** [June 8, 2021, 8:38pm UTC](https://forums.unrealengine.com/t/adding-and-removing-actors-from-an-array/484587/3 "2021-06-08T20:38:52Z")

</div>

Ok… I see what it’s doing, but I’m having issues.

Walking atop the boxes, as I need to happen, the “On Component Hit” doesn’t do anything. I tried it with “On Component Overlap” but its very laggy and only seems to affect every other box, not destroying around half of the objects.

I also can’t figure out what that “SET” node, or the “–” node are… I can’t find them.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [June 9, 2021, 6:36am UTC](https://forums.unrealengine.com/t/adding-and-removing-actors-from-an-array/484587/4 "2021-06-09T06:36:18Z")

</div>

> Walking atop the boxes, as I need to  
> happen, the “On Component Hit” doesn’t  
> do anything.

I was under the impression you already had destroying mechanics in play since the stripped boxes were exploding - I’m not suggesting a new method; use what you’ve got. I was merely suggesting a way to count.

_The_ Set node is just _a_ Set node - it’s an integer variable, it keeps the track of the number of boxes left. You can get / set variables:

 ![341040-screenshot-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/9/3/493088870489c4b2cc27029d3b120e9504d45630.png)

Which is equivalent to reading / writing data.

* * *

Were I to suggest an interaction method for destroying actors we stepped on, I’d probably opt for attaching a smallish sphere collision to where player’s feet are and use `on END Overlap`:

 ![341062-screenshot-4.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/e/8/ee893e0dc32065fef6998a0aadbb5f424af058b4.jpeg)

[![Image from Gyazo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/d/0/1d0451c51661dea166da6d96627cb04faea5f518.gif)](https://gyazo.com/ebf478732281849ab07edb5331504d12)

---

<div class="post-metadata">

**Author:** ![Todeswalzer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Todeswalzer](https://forums.unrealengine.com/u/Todeswalzer)\
**Post date:** [June 9, 2021, 11:23am UTC](https://forums.unrealengine.com/t/adding-and-removing-actors-from-an-array/484587/5 "2021-06-09T11:23:08Z")

</div>

I had already had destroying mechanics, but I had to modify them to incorporate your incredibly helpful guidance, and after a little bit of fiddling about, I’ve gotten it to work, thank you so much for your help, it really is greatly appreciated.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [June 9, 2021, 11:27am UTC](https://forums.unrealengine.com/t/adding-and-removing-actors-from-an-array/484587/6 "2021-06-09T11:27:07Z")

</div>

Ah, cool - glad to hear that. Good luck with the rest!
