After ive added my own implementation of the player controller my pawn is spawned into the world but not posssed.
I dont really know what to do :S
I can see in my editor that it spawns the player but also spawns the spectator class. This is my BP_Playercontroller.cpp:
#include "Players/ABPlayerController.h"
#include "Players/ABPlayerState.h"
#include "UI/ABHUDWidget.h"
void AABPlayerController::CreateHUD()
{
if (UIHUDWidget)
{
return;
}
if (!UIHUDWidgetClass)
{
UE_LOG(LogTemp, Error, TEXT("%s() Missing UIHUDWidgetClass. Please fill in on the Blueprint of the PlayerController."), *FString(__FUNCTION__));
return;
}
// Only create a HUD for local player
if (!IsLocalPlayerController())
{
return;
}
// Need a valid PlayerState to get attributes from
AABPlayerState* PS = GetPlayerState<AABPlayerState>();
if (!PS)
{
return;
}
UIHUDWidget = CreateWidget<UABHUDWidget>(this, UIHUDWidgetClass);
UIHUDWidget->AddToViewport();
// Set attributes
UIHUDWidget->SetCurrentHealth(PS->GetHealth());
UIHUDWidget->SetMaxHealth(PS->GetMaxHealth());
UIHUDWidget->SetHealthPercentage(PS->GetHealth() / FMath::Max<float>(PS->GetMaxHealth(), 1.f));
}
UABHUDWidget* AABPlayerController::GetHUD()
{
return UIHUDWidget;
}
void AABPlayerController::OnPossess(APawn* InPawn)
{
AABPlayerState* PS = GetPlayerState<AABPlayerState>();
if (PS)
{
// Init ASC with PS (Owner) and our new Pawn (AvatarActor)
PS->GetAbilitySystemComponent()->InitAbilityActorInfo(PS, InPawn);
}
}
void AABPlayerController::OnRep_PlayerState()
{
Super::OnRep_PlayerState();
// For edge cases where the PlayerState is repped before the Hero is possessed.
CreateHUD();
}
My game mode and game state are blueprints that are mostly empty. The map i have only has a player start component (not the actual character).
Can anyone tell what ive might done wrong?