Download

PlayerController Possess and input problems (c++).

Hello,

I’m spawning two characters from blueprints in my level ::BeginPlay(). I need to assign a different PlayerController depending on various options the user has picked. So I do the following:

auto playerController = GetWorld()->SpawnActor<AHumanCharacterController>(AHumanCharacterController::StaticClass());
playerController->Possess(character);

However, after I’ve called ::Possess() I see “Calling IsLocalController() while Player is NULL is undefined!” in the log window and it keeps pumping out this message while the game is running, the input binds I have set up in the controller aren’t getting triggered either. Using the PlayerControllerClass in the GameMode isn’t an option as these characters need different controllers for input types and AI control, I’ve been looking at this all day and I’ve hit a wall, what am I doing missing?

// .H:
UCLASS() class API AHumanCharacterController : public APlayerController
{
GENERATED_BODY()
protected:
void test();
virtual void SetupInputComponent() override;
virtual void Tick(float DeltaTime) override;
public:
};
// .CPP
void AHumanCharacterController::SetupInputComponent()
{
Super::SetupInputComponent();
InputComponent->BindAction(TEXT(“ButtonB”), IE_Pressed, this, &AHumanCharacterController::test);
}
void AHumanCharacterController::test()
{

}
void AHumanCharacterController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}

Thanks,
Mike