How to disable player's movement on one axis

Hi all, I’m trying to disable player movement on one axis but it isn’t working, is there any ideas how I can get it to work?
This is the code that isn’t working in the constructor of my character:


GetMovementComponent()->bConstrainToPlane = true;
GetMovementComponent()->bSnapToPlaneAtStart = true;
GetMesh()->BodyInstance.CustomDOFPlaneNormal = FVector(0.0f, 1.0f, 1.0f); 

Go to your BP character, and check if the movement component is also set accordindly.

Theres another way to reach this. Just try to add some constriant code in players movement input.

It works when I set it in blueprints but when I try to set it in code it doesn’t work? I tried this:


 GetMovementComponent()->SetPlaneConstraintNormal(FVector(1.0f, 0.0f, 0.0f));


If your derived BP is already created, then changes in your code may not be reflected in the BP after compiling. That’s why it usually appears the yellow arrow on the right of the property in the BP.

So am I not able to change the costraint axis during runtime through code?

The issue only happens if, for example, you set the constraints directly in the constructor.

That was the problem, I put the code in beginplay and it now works! Thank you!