Can a Pawn bind input for a PlayerController?

I am still a bit confused by the PlayerController class. If I understand it correctly it is the class that can possess different pawns, so it shouldn’t handle game logic on its own right?

I tried to bind an action from the pawn itself like this


void AArenaCharacterProxy::PossessedBy(AController* NewController)
{

	AArenaPlayerController* APc = Cast<AArenaPlayerController>(NewController);
	if (APc)
		APc->InputComponent->BindAction("PrimaryAction", IE_Pressed, this, &AArenaCharacterProxy::Test);
}


but this code results in a crash. In fact the crash happens inside of


FInputActionBinding& UInputComponent::AddActionBinding( const FInputActionBinding& Binding )

It seems that it can’t read the memory of


TArray<struct FInputActionBinding> ActionBindings

What have I done wrong? Maybe the first posses happens too early? Do I need to initialize something first?

I think I know why this doesn’t work. I just realized that PossesBy is only called on the server which means that I probably have to call a client side rpc from PossesedBy.

Update:

Yes that was the problem, just send a client side rpc.

Consider overriding OnRep_Controller which is already declared for you in Pawn.h:



	/** Controller currently possessing this Actor */
	UPROPERTY(replicatedUsing=OnRep_Controller)
	AController* Controller;


Are you sure that OnRep_Controller is what I need? I think OnRep_Controller is called every time when some variable changes on the server and I only need to bind the input once.

Currently I am doing it like this:


void AArenaCharacterProxy::PossessedBy(AController* NewController)
{
	Super::PossessedBy(NewController);
	ClientPossedBy(NewController);
}

void AArenaCharacterProxy::ClientPossedBy_Implementation(AController* NewController)
{
	AArenaPlayerController* APc = Cast<AArenaPlayerController>(NewController);
	if (APc && Role < ROLE_Authority){
		APc->InputComponent->BindAction("PrimaryAction", IE_Pressed, this, &AArenaCharacterProxy::Test);
	}
}

This currently works but I am actually not sure how UE4 handles pointer in an RPC.