Accessing character movement properties from a controller causes a crash?

So, I’m pretty new to Unreal Engine. I very much enjoy its extension on C++, it’s very thoughtfully developed.

But I’m running into a weird problem when trying to access the character movement properties from my controller. I have the following code in my player controller constructor:

GetCharacter()->GetCharacterMovement()->MaxWalkSpeed = 200

For some odd reason this causes the editor to crash when running the game, and until I compile the code without it, the editor will crash during the splash screen.

I feel like I’m missing something here. Why would this cause a crash? There must be a reason. Is it because the player controller class initializes before the character class does? That’s the only reason I can think of.

Thanks for reading. Hope someone can help!

EDIT #1:

I noticed that if I place that line in another function such as a movement function it runs fine. This further makes me think the problem is the character class has not yet initialized when the player controller constructor is called.

Hi 1Studios,

Probably is because on PlayerController constructor this controller do not have any Character possesed. The PLayerController need to be created and then he can possess
the Pawn, because of this in the contructor the GetCharacter is NULL.

A good way to avoid this kind of crash is checking by NULL before using your possessed character.

ACharacter* Char = GetCharacter();
if(Char)
{
	Char->GetCharacterMovement()->MaxWalkSpeed = 200
}

On the other hand, the config for MaxWalkSpeed like other character properties is better to have them on your character constructor.

Cheers

Exactly what I though! Thank you very much