Storing Pawn once for all in Player Controller

Hello !

I didn’t find the answer to that, so here is my question : Can I cast and store the pawn in his controller once for all ?
I’m using my Controller to handle player’s inputs, and the Pawn should NOT change during the game. At first, I was handling everything directly in the Pawn itself and it was working fine, but for training purposes, I’m willing to switch everything to the Controller.

So basically what I’m trying to do is to call the moving function that is inside the Pawn from the Controller. The following code works, but force me into casting the pawn for EVERY functions. Plus, this is going to be called everytimes the player try to move or rotate the camera. I tried to make a ACommander * variable in the .h of the Controller and set it like below in the constructor so it’s set once for all, but it doens’t seem to work.

void ACommanderController::Test()
{
	auto pawn = Cast<ACommander>(this->GetPawn());
	if (pawn)
	{
		pawn->TestFunction();
	}
}

Any idea how I could cast+store the pawn once ? So I could write something like :

    void ACommanderController::Test()
    {
    	pawn->TestFunction();
    }

Thanks !

The Character Pawn contains all of the movement functions. For most functions such at movement you will have to cast to the Character Pawn repeatedly unless you store a reference to it inside of an variable.

Personally I would not recommend that you store your movement control data in the Player Controller as it is not designed for that.

It can be done with a bit of work but it is unnecessary.

The doc says that the Controller is made for complexe cases and for persistence purposes.

“unless you store a reference to it inside of an variable.”
This is exactly what I’m asking for. Thing is, at the moment of Controller creation, the Pawn or the link between the 2 entities does’nt seem to exist. So if I cast and store the Pawn in the Controller’s constructor, it doesn’t work.