UE 4.15.1 BindAxis causes crash

Hello, I’ve updated to 4.15.1 hotfix and started a new project and I encountered several errors in C++.

First one:


//This is called inside Pawn constructor
PawnMesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("PawnMesh"));
PawnMesh->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepWorldTransform);
PawnMesh->SetWorldLocation(FVector(0.f, 0.f, 70.0f)); // <--- this line gives me "UE4Editor.exe has triggered a breakpoint."

Second one:


//Overriden function inside PlayerController
void ALPlayerController::SetupInputComponent()
{
	//Gameplay axis bindings
	InputComponent->BindAxis("MoveForward", this, &ALPlayerController::MoveX); // <---- causes exception "Exception thrown: read access violation. this was nullptr."
	InputComponent->BindAxis("MoveRight", this, &ALPlayerController::MoveY);
}

MoveX and MoveY are just normal void UFUNCTIONs.

Not sure why it’s causing that. Also MoveForward & MoveRight are set in the Input config in the editor.

My first guess is that InputComponent is not valid at that point. I am not 100% sure why but I would try calling the super first, like:



void ALPlayerController::SetupInputComponent( )
{
    Super::SetupInputComponent( );
    InputComponent->BindAxis("MoveForward", this, &ALPlayerController::MoveX);
}


If that doesn’t work, try checking against InputComponent:



void ALPlayerController::SetupInputComponent( )
{
    Super::SetupInputComponent( );
    if(InputComponent)
    {
        InputComponent->BindAxis("MoveForward", this, &ALPlayerController::MoveX);
    }
}


I don’t know how the PlayerController gets reference to the InputComponent and I would look at where that is created.

1 Like

Oh my… it worked. It’s not the first time I forget calling Super:: … thanks. It’s so easy to miss this line …