How do I remove items from an array efficiently?

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?

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

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.