How to properly detect Begin&EndOverlap with multiple actors?

I have a row of traps which I place with a TrapActor-mousecursor.
When the cursor overlaps a trap, it turns red and does not allow placement.
When it does not overlap it turns green and allows placing the trap.


This goes fine with a ‘IsOverlapping’-boolean based on OnComponentBeginOverlap and OnComponentEndOverlap,
however, when more then one trap is placed directly against each other while placing another one, and then move out of the overlapped Actor space into the space of an already placed TrapActor it will indicate that there is no overlap.
I’ve tried many things to bypass this behavior but without success. It seems to me like this should be something that is used a lot in a lot of gametypes. Is there an example of what would be the proper way to do this?

If a BeginComponentOverlap of Actor2 is detected while the EndComponentOverlap of Actor1 has not yet executed, then the next EndComponentOverlap of Actor1 will set all overlapped events to NotOverlapping, while still overlapping with Actor2.

I’d assume that something like this should have worked, but it doesn’t:

Use integer instead. Increase it on BeginOverlap and Decrease on EndOverlap. After decreasing test it against 0 (if it is - no overlaps).

https://docs.unrealengine.com/latest/images/Engine/Blueprints/UserGuide/Events/BeginOverlapEX.jpg

From: Events | Unreal Engine Documentation

Thanks for your response, I had not thought of using incrementing integers which seems indeed the better way to do it.
However, the results for me are the same. As soon as a second actor has initiated a BeginOverlapEvent, it does not go from 1 to 2, but from 1 to 1. It doesn’t increment.
(with or without the first branch)

Um. In Your graph You’re testing if Other actor is SELF? Its’ clearly stated it should be OTHER actor.

A begins overlap B. In B You’re asking: “Is this other actor B?” You should ask, “Is that A” instead.

Thanks, I corrected it and replaced the screenshot.

In the previous one I bypassed the first branch because I didn’t think it was a required part of the logic, and then after I tested it with the branch included as demonstrated in the new screenshot but with the same result.

Oh. Don’t set the variable. You already should know, that other actor is Trap. Just Cast actor to Trap, if casting will succeed then go next. And just ignore failed ones.

But I have to set the overlapped actor because when it gets spawned (as mouse cursor and before any overlap events) its ActorName is not ‘MouseSpecificTrap’ (the name of the blueprint), but ‘MouseSpecificTrap1’, and even though its always 1, I’m unaware of a way to reference that without setting it first. (also, when multiple traps are spawned, they are not all called ‘SpecificTrap’, but ‘SpecificTrap1’, ‘SpecificTrap2’… etc.)
But aside from that, … is that first branch really relevant for this logic? shouldn’t it just always increment and decrement, independent of the same or different overlapping actors?

Casting doesn’t rely on names. It just asks “Is this Actor instanced from Class A?”

Casting might not, but overlap does.

I realized what i was doing wrong and I have it working now.
Thanks a lot for your help :slight_smile:

The mistake I was making was not realizing that every spawned actor is its own instance with its own unique copy of the actor variables. TrapActor1 might have registered a BeginOverlap and increment a counter, but TrapActor2 from the same blueprint and with the same functions and variables does not increment from TrapActor1’s values, but from its own, starting at 0.

The solution was to move the incrementing counter to PlayerController and count from there. (Although I guess a better way would be to do the counting in a dedicated MouseActor, but I have yet to ponder the consequences of that, so for now this will do just fine :slight_smile:

Thanks again for the help, S-ed, Much appreciated! :smiley:

Okay. Good that You’ve found a solution. Don’t forget to mark topic as resolved.