Hi everyone,
I have created a new third person project to check if this can work and as I thought it does not. I am handling the input in the player controller and sending the value to the character. And it gives a null reference, What I did was this.
Created a new third person project (C++ not Blueprints)
Created a PlayerController and added necessary components for handling only the forward movement
PlayerController .h
ADedicatedServerTest_PC(const FObjectInitializer& ObjectInitializer);
// Called to bind functionality to input
virtual void SetupInputComponent() override;
void MoveForward(float AxisValue);
PlayerController .cpp
ADedicatedServerTest_PC::ADedicatedServerTest_PC(const FObjectInitializer& ObjectInitializer) :Super(ObjectInitializer)
{
}
void ADedicatedServerTest_PC::SetupInputComponent()
{
Super::SetupInputComponent();
InputComponent->BindAxis("MoveForward", this, &ADedicatedServerTest_PC::MoveForward);
}
void ADedicatedServerTest_PC::MoveForward(float AxisValue)
{
Cast<ADedicatedServerTestCharacter>(this->GetControlledPawn())->MoveForward(AxisValue);
}
And removed this functionality from the Character cpp file.
then create a Blueprint extension of the game mode and set the character and the player controller defaults there. And set the blueprint extended game mode as the default.
Everything works when playing normally i.e locally but when I tick the ‘Dedicated Server’ the editor crashes at the ‘if’ statement in the Character in this part of the code. What caught my eye here was the in Visual Studio’s Locals windows said that ‘this’ has a value of 0x0000000000000000 .
void ADedicatedServerTestCharacter::MoveForward(float Value)
{
if ((Controller != NULL) && (Value != 0.0f))
{
// find out which way is forward
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
// get forward vector
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
AddMovementInput(Direction, Value);
}
}
I do not understand what I am doing wrong or what I am not doing at all
can someone explain why is this happening