How to only interact with one actor at a time?

hi all so im doing this to interact with objects/actors in my game. But the thing is right now if theres a bunch of actors in the same place,my character interacts with all of them at the same time. What would be a good way to make sure i can only interact with one at a time?

Interacting with all of them is exactly what the ForEach Loop is. If you want to only interact with one, you have to either remove the ForEach Loop and select an actor otherwise, or keep the Loop and add some more checking logics after it, so that the Interact function would only apply to one at a time.


Depending on how you want to interact with them, you have a number of options. Like selecting a random one in range, or interacting with the closest one, or whatever you want.

Would you could do is instead get all the actors you are overlapping from your overlap component.

Then filter by the interface.

Finally check which is closest to the center of the overlap and call interact on that.

You could also break the loop the first time you call interact

Or you can cycle through all the items available items and select the one you need, like it was implemented in Severance: Blade of Darkness. Anyway, first of all you have to decide exactly how you want to interact with the items, then you can start working out the solution.

breaking it worked for me.
not sure if this is the best way of interacting with items tho… seems a bit expensive to make an array with all the actors with interface in the level

It depends on how many objects there are. You can start with getting the overlapping actors, as @HarryHighDef suggested, and only then check for their interfaces. I’d say a better way would be setting a custom collision preset for the objects you can intertact with, and only overlap those; thus you won’t have ground/walls/other objects in the Overlapping Actors array.


So if you do it right, you can Get Overlapping Actors and don’t even check if they have tags/implement interfaces, you will only have the objects you can interact with in your array.


Next, if you use Break to break the ForEach after interacting with the first one, maybe you don’t even have to do that. For example, if interacting means picking it up and placing it in the inventory, and the object is no longer in the level, you can simply Get an object from the array by index 0 — you pick it up, and the next time you press E, another object will be under index 0, and so on until there are no more overlapping objects. In this case you’ll have to check if Array Length > 0, but that would be better than using a ForEach loop for only one action.


Hope it helps.