# How do I remove items from an array efficiently?

**URL:** <https://forums.unrealengine.com/t/how-do-i-remove-items-from-an-array-efficiently/378523>\
**Category:** Editor Scripting\
**Tags:** arrays, event-dispatcher, get-all-actors-from-, unreal-engine, level-blueprint, Blueprint, question\
**Created:** [December 6, 2016, 6:58pm UTC](https://forums.unrealengine.com/t/how-do-i-remove-items-from-an-array-efficiently/378523 "2016-12-06T18:58:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![VagrantProfile](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VagrantProfile](https://forums.unrealengine.com/u/VagrantProfile)\
**Post date:** [December 6, 2016, 6:58pm UTC](https://forums.unrealengine.com/t/how-do-i-remove-items-from-an-array-efficiently/378523/1 "2016-12-06T18:58:29Z")

</div>

Hey Guys,

So I’m currently making a Pac-Man game in UE4. I want to make it, so that my level is over when Pac-Man collects all of the pellets I’ve placed around the level. I’ve created a Pellet Blueprint and have placed a couple hundred pellets around the maze. Now, I want to end the level when all pellets have been collected (my Pellet BP is set up to destroy each pellet when I overlap it.)

How can I set up a system to check that all pellets have been eaten? I THINK I’m on the right track? (see screenshot)

What I currently have in my LEVEL Blueprint is what you see below…I’m getting all actors of the Pellet class and finding out how many items are in that array upon Begin Play. What I DON’T know how to do is send a message from the Pellet BP to the Level BP to reduce that array by 1 with each pellet eaten. I thought to use Event Dispatchers, but couldn’t figure out how to set i up properly.

Any suggestions here on how I can end my level efficiently when all pellets are eaten?

 ![117642-img_1648.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/d/7/5d7c763748b39056105bb92eeaf84975f43f664a.jpeg)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_dceb25d5](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_dceb25d5](https://forums.unrealengine.com/u/anonymous_user_dceb25d5)\
**Post date:** [December 6, 2016, 8:23pm UTC](https://forums.unrealengine.com/t/how-do-i-remove-items-from-an-array-efficiently/378523/2 "2016-12-06T20:23:23Z")

</div>

It’s not exact but this might guide you in the right direction…

> **[Loop thru array and remove items/actors](https://forums.unrealengine.com/questions/182798/loop-thru-array-and-remove-itemsactors.html)**
>
> Hello, Here is what im trying to do: Create array of actors Loop thru it every second and check if actor is above pawn If it is, then delete actor Here is my implementation in BP, but logic is wrong and it doesnt quite work as expected. I know...

Follow the top comment and use a ForEachLoop as well as marking the correct index along the way. I use the same method for my inventory system and it works perfectly.

Also to send the message like an index count from your pellet BP to the level BP to me seems less modular then having the same variable in a GameHUD UMG and cast to firstpersoncharacter and get the GameHUD object from there to set that variable.
