I figured out what the problem is, but now I have even bigger problems. Apparently I couldn’t spawn an AAzurePlayerController when I used autopossess in the constructor like so AutoPossessPlayer = EAutoReceiveInput::Player0;
Here’s the code that “works”:
LocalController = GEngine->GetFirstLocalPlayerController(World);
AAzureCharacter *PlayerCharacter = World->SpawnActor<AAzureCharacter>(AAzureCharacter::StaticClass());
PlayerCharacter->AIControllerClass = AAzurePlayerController::StaticClass();
PlayerCharacter->SpawnDefaultController();
AAzurePlayerController *Ctrl = Cast<AAzurePlayerController>(PlayerCharacter->Controller);
if(Ctrl == nullptr)
DebugMessage("Controller is nullptr");
else
DebugMessage("Controller isn't nullptr");
And here are the results with autopossess:
And without autopossess:
Now that I’ve successfully spawned the AI controller I’ve lost all axis mapping and action mapping inputs so none of my mouse movement or clicks are registering. Not to mention the camera which is supposed to be attached to the character object itself using a spring arm is now displaying a view straight from the character itself, rather than giving the nice top down view.
Here’s how I set up my camera:
In constructor:
CameraSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraSpringArm"));
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("TopDownCamera"));
...]
void AAzureCharacter::EnableTopDownCamera()
{
CameraSpringArm->AttachTo(RootComponent);
CameraSpringArm->TargetArmLength = CameraOffset;
CameraSpringArm->SetWorldRotation(FRotator(-60.f, 0.f, 0.f));
Camera->AttachTo(CameraSpringArm, USpringArmComponent::SocketName);
}
And this is the code for the player inputs:
void AAzureCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAction("LeftMouse", IE_Pressed, this, &AAzureCharacter::MoveCharacter);
PlayerInputComponent->BindAction("RightMouse", IE_Pressed, this, &AAzureCharacter::SetRightMouseDown);
PlayerInputComponent->BindAction("RightMouse", IE_Released, this, &AAzureCharacter::SetRightMouseUp);
PlayerInputComponent->BindAxis("MouseX", this, &AAzureCharacter::RotateCameraXAxis);
}
Whenever I touch something something immediately breaks, I don’t know what to do