Creating a can walk off ledge in c++

I’m currently working on a puzzle game, and for certain levels I don’t want the player to be able to walk off the edges. I’m trying to do as much in c++ as possible, but everything I’ve seen about doing this is just using the can walk off ledge field in the blueprints. I’m using the WASD movement from Epic’s FPS tutorial here: and I have jumping to enable the user to navigate the level. The only possible thing I can think of is to make sure that movements have the precondition that they won’t make me lose my collision status. Basically, if I’m touching the ground and colliding with the floor I can only move if I’ll continue to collide with the floor, and this status is removed if I’m in the air. Does anyone have a better idea because I feel like I’ll have trouble trying to implement it this way. Thanks in advance for anyone who bothered to read this, regardless if you have ideas or not.