How to have a list of actors that can be added/removed at runtime

I am used to unity so this may be a simple stupid question, cbut Ive been researching it and cant find the answer.

I want to make a list of enemies as the projectile hits it and remove from list when the enemy is dead.
Also want to damage multiple enemies on the list when one is damaged but thats for a different day.

How do i do this? I tried finding a list variable but cant.
I also want the projectile to add to this enemy list, while the enemy list is stored on the character.

I would post the code but im literally stuck at square one just trying to find the list variable.
In unity, arrays arent something you edit at runtime but I am not sure if they work the same way in Unreal 5.

Well first, from you parent enemy bp, you can add some generic function (function interface) if needed.

Then from your character bp:
Create a variable of type Actor


Change it to an array
image

Create some custom event (or function interface)

Add input param from your custom event

From your Enemy Bp parent:
Cast to our character (or use of function interface) to remove it from the array

Then you can just call these event in your character bp when you hit them.

And yes we can edit values of an array in runtime in unreal. Just avoid doing for each if possible and make use of inbuilt function such as FindItem or Contains.

1 Like

thank you! That makes sense and helps a lot!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.