Begin Overlap On 2 Different Objects

Hello! I made a crouch system that detects if something is blocking the player so he won’t be able to uncrouch. When the character is under 1 object everything works fine. If I go under 1 object and start overlaping another object at the same time the second object will be ignored and I will uncrouch as shown in the GIF. How can I make it so it always detects if something is overlapping? Imgur: The magic of the Internet
Thank you in advance!

Hi James, the reason why its happening is because the End Overlap logic doesn’t know if there is a second overlapping object. So as soon as the first object stops overlapping, HasObjectAbove is set to False.

An easy way to fix the issue would be by keeping track of the number of overlapping objects using an int variable. You increment it by 1 every time a roof object begins overlap, and decrement by 1 (with a min value of 0) when a roof object ends overlap. And if the new value of the int is > 0, you know that there is an object above your character and needs to be in crouched position. If not, you can uncrouch the character.

I followed the steps, but I can’t find how to limit the int to not go below 0

Okay I think I got it, I put a branch that let’s input in only if the int is >0

To put the 0 limiter, you can use the Max (integer) node. Set one of the values to 0 and the other as our Int variable that was used for tracking. This node will return the highest value among the two, and hence will make sure that you don’t end up with negative values.

Also in blueprints, the more the number of nodes that you execute, the slower it gets since more time is spent on talking to the underlying layer than running these small math operations. So if you can get the result in a single node (like the max), you are usually better off than using multiple nodes to achieve the same result.

thank you alot, it worked perfectly! I also had to change from a box collision to a capsule collision to be more precise!