Problem with disabling input via C++ in multiplayer game

I’m trying to write Dash() function that will move my character in some short period of time.
During this time I want to prevent my character form moving in different directions, jumping etc. so I want to disable input. I got UFUNCTION(Server,Reliable,WithValidation) specifiers over my Dash() function becouse I think it is quite important for gameplay and should be called on server.
So far I have Dash_Implementation that calculates final position of dashing, sets up timer that will call function to move player over some time and it works well.
I want to disable input in first lines of Dash_Implementation and enable it again when player reach final position.
Here is code i tried but it’s not working

#1

APlayerController* PlayerController = Cast<APlayerController, AController (GetController());
DisableInput(PlayerController);

#2

if (GEngine)
	{
		APlayerController* PlayerController = GEngine->GetFirstLocalPlayerController(GetWorld());
		DisableInput(PlayerController);
	}

Any ideas what’s wrong here?
Thanks in advance for your help :slight_smile:

EDIT: i think the problem is that i disable input on server but clients can still move the player around

For the guys in the future. I solved it this way.
I added this public funtions to my PlayerController.

void ABasePlayerController::Disable()
{
	DisableInput(Cast<APlayerController>(this));
}

void ABasePlayerController::Enable()
{
	EnableInput(Cast<APlayerController>(this));
}

Now I’m able to do this

Cast<ABasePlayerController>(GetController())->Enable();

from my custom Character.

It is really convenient and if it was written in PlayerController there would be less casting.

1 Like

This guy from the future thanks you! :slight_smile: