Just as the title says, my goal is to create a boundary which the player resides in and cannot leave.
In order to do this, I created an actor that has a box collision. The collision is set to OVERLAP ONLY.
The actor is placed inside the box. When the actor leaves the box collision, I constrain its position to the edges of the box’s extent. So let’s say the box extent goes to X=300. If the actor starts at 0,0,0 and moves to position 302, I reset its location to 300. This happens similarly for the Y and Z axis, effectively trapping the actor within the box. The actor should “stick” to the edge of the collision, and works fine while doing this during Tick.
I originally did this logic during event Tick, but due to the FUD against using Tick, especially since the code gets called when we’re freely moving inside the box, I decided to try calling this code only during EndActorOverlap.
However, I’ve discovered that when SetActorLocation is called during the event EndActorOverlap, the actor has a ton of momentum or force applied to it out of nowhere. The actor can have so much force applied, that it flings itself to the other side of the collision bounds and bounces off the edge. This can happen a few times. I don’t have physics turned on, and calling the same code from Event Tick instead shows zero problems! So it’s not a problem with the concept of what I’m doing… the engine is perfectly fine doing this during Tick.
Additionally, I can scale back the concept even more… if during EndActorOverlap I set the Actor’s position to 0,0,0… the center of the box… the physics issue STILL happens. I can also set the position to very far OUTSIDE the box, and the actor still has this force applied… so much so it’ll fly off 60,000+ units away. So it’s not an issue with the actor “being on the edge of overlapping and not overlapping” and it’s not an issue with “the actor stops overlapping but then immediately starts overlapping again”… Either way, it works during Tick!
My last thought is, maybe ActorEndOverlap is called during a bad time in physics, and maybe I can set Event Tick to mimic this behavior. I’ve set the actor’s Tick group to Pre, During, Post, and Post-Update and all of them work perfectly fine! I can’t even make Tick behave the same as EndActorOverlap.
A few event problems like this have happened to me, which I could “hack” by adding a Delay 0 node to them. When I do my “Clamp Pawn Position To Bounds” logic during EndActorOverlap, and after a Delay node, then the behavior is fairly close to what I want/expect… the momentum is still being applied, but to a much lesser degree. This causes the actor to “bounce” against the side of the box collision instead of “stick” to it… closer to what I want, and less of a problem… but definitely not the expected or DESIRED outcome.
At this point, this definitely seems like a bug… definitely unexpected behavior.
I’ve made a new project with the bare essentials in order to show off this problem. I started a new blank project, made a simple pawn and an actor for the player boundary, and set the camera to look down into this area. Please open the PlayerBounds event graph and switch the logic between Event ActorEndOverlap and Event Tick to see the results.
Tick event is king. Stop bad mouthing Tick.