Hi everyone,
for some reason I’m having a problem which makes the entire editor crash.
I have a basic PlayerController class that binds to input axises. Inside the functions for the handling of input I call some functions such as MoveHorizontal/MoveVertical etc. from a possessed Character class.
Inside those function I just get the character movement component object of the class and use AddInputVector to modify the movement of the character.
Now, while everything is working fine for single player purposes… the entire editor crashes when I try to play in a multiplayer environment. As a matter of fact, I can’t even check for the presence of a null pointer since the GetCharacterMovement itself crashes immediately.
If this->GetCharacterMovement() crashes immediately, then your ‘this’ value is not valid. Somehow you’ve managed to get a pointer to a non-existent player controller or character.
void ABasePlayerController::HorizontalMovement( float _x_axis )
{
ABasePlayerCharacter* pawn = Cast( GetPawn() );
check( pawn ); // The assert fails here. Only in Multiplayer though
if ( pawn != nullptr )
{
pawn->MoveHorizontal( FMath::Clamp( _x_axis , -1.0f , 1.0f ) );
}
}
I’ve narrowed the error down to the pawn pointer inside the controller having a null value (or at least some problem with it). The assert fails if the game is played in multiplayer.
However, if I remove the check(pawn) and just leave the check for nullptr the game works properly. Thing is, I’ve also tried and used an else whose code block never gets called.
Whose player controller are you calling that on? Only the owning client’s PC gets replicated to the client, so if you try to use another client’s, it will be null and that method will fail.