Is there a way to cancel the un crouch function.

I’m new to unreal engine and I’m trying to set up a crouch system using the built-in function.

So, this setup works fine. until I walk under something and try to un crouch then crouch before walking out from under it. even thou I called crouch again it un crouches when there is no longer anything in the way. so is there a way to cancel the un crouch function or something.

Hi there!

I’m not sure to understand.
You’ve tried to UnCrouch while having something above your head right ? And then, if you want to Crouch again it won’t work ?

Sorry I wrote the explanation pretty confusing. I think this might be a bit better.

When I run UnCrouch under an object it stays crouched like it’s supposed to, but when I run Crouch again while still under the object it will UnCrouch when the object is no longer in the way without me running the UnCrouch function again. So since UnCrouch was blocked by an object it keeps running until it’s clear even thou I called Crouch again.

Could do a quick line trace straight up before calling uncrouch, adda branch and if trace hit something do nothing, and on false, call uncrouch. Or use capsule/sphere trace that matches size of standing capsule.

Err, on second thought, I think the flip flop is just breaking it. Try doing this instead:

Ignore wires going offscreen to the right. Those are just sending BPI messages to follower NPC telling them to (un)crouch too.

the line trace would work but then if I try to UnCrouch under an object it would just not call the function rather than un crouching once the object was no longer in the way.

the branch node method works fine to, but if I go under an object hit UnCrouch then Crouch again it still un crouches when the object is no longer in the way, rather than staying crouched. but it still works good enough I might use it if I can’t figure this out.

thank you for your help.

Would probably need to override character movement logic in c++ to preserve a crouch after calling uncrouch and crouching again before clearing obstacle.

You should then add a capsule or line trace before calling the uncrouch function like @illspiritx was saying.
And you should make sure that the Character isn’t already crouch before calling the Crouch function.

Those modifications should be enough to fix your problem.

that would work. but I don’t know what I am overriding. when UnCrouch is called it sets the WantsToCrouch boolean to false. but I dont know where it goes from there.

I can’t find it either, presumably it’s checking for bEncroached somehow when deciding to uncrouch later. Maybe in CharacterMovementComponentAsync.cpp?

I think at this point it might be easier to make my own crouch system.

I got it figured out.