# Use code to disable player input unreal engine

I have seen a lot of ways to use the node based visual scripts to stop player input; However, I have not seen a single example of how to disable the player input in visual studio?

You can disable player input using the function:

AActor::DisableInput(APlayerController* PlayerController)

This should be called on the actor you wish to disable input for. You need to have a pointer to the current player controller, and pass this as the function's argument. You can easily get the first (and usually only, in single player game) player controller from the current world:

UWorld::GetFirstPlayerController();

Quick example, with PlayerPawn being a pointer to the AActor that you wish to disable input for:

APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
PlayerPawn->DisableInput(PlayerController);


Documentation on PlayerInputComponent

It's been quite some time since I've used UE4 in a moderate-sized project, but what I would do first is:

1. Get UInputComponent* Temporary = PlayerInputComponent;

2. Set PlayerInputComponent = nullptr; to block input

3. Later restore input by PlayerInputComponent = Temporary;

You might be able to use C++ standard move semantics with UE4, though I wouldn't guarantee it because usually UE4 does things in it's own weird but necessary way. What I posted above would be the first thing I'd do, so no guarantees if it works. Would be great if someone could confirm or deny.

ALSO: Please note that Visual Studio is not the only way to access/modify C++ code in UE4 environment. You can basically use any text editor to do so.

Set (Pawn)->InputEnabled() to true or false. If you can find a blueprint node to do what you want, there's a good chance the code function is very similarly named.