Download

Includes needed when redefining existing code?

Hello,

I’m trying to spawn 2 pawns per player.
To do this, I created a MyGameMode which redefines the function “void RestartPlayer(class AController* NewPlayer);”.

I copied the code of the function RestartPlayer from the class GameMode to the class MyGameMode.


void AGameMode::RestartPlayer(AController* NewPlayer)
{
    if ( NewPlayer == NULL || NewPlayer->IsPendingKillPending() )
    {
        return;
    }
 
    UE_LOG(LogGameMode, Verbose, TEXT("RestartPlayer %s"), (NewPlayer && NewPlayer->PlayerState) ? *NewPlayer->PlayerState->[PlayerName] : TEXT("Unknown"));
 
    if (NewPlayer->PlayerState && NewPlayer->PlayerState->[bOnlySpectator])
    {
        UE_LOG(LogGameMode, Verbose, TEXT("RestartPlayer tried to restart a spectator-only player!"));
        return;
    }
 
    AActor* StartSpot = FindPlayerStart(NewPlayer);
 
    // if a start spot wasn't found,
    if (StartSpot == NULL)
    {
        // check for a previously assigned spot
        if (NewPlayer->StartSpot != NULL)
        {
            StartSpot = NewPlayer->StartSpot.Get();
            UE_LOG(LogGameMode, Warning, TEXT("Player start not found, using last start spot"));
        }
        else
        {
            // otherwise abort
            UE_LOG(LogGameMode, Warning, TEXT("Player start not found, failed to restart player"));
            return;
        }
    }
    // try to create a pawn to use of the default class for this player
    if (NewPlayer->GetPawn() == NULL && GetDefaultPawnClassForController(NewPlayer) != NULL)
    {
        NewPlayer->SetPawn(SpawnDefaultPawnFor(NewPlayer, StartSpot));
    }
 
    if (NewPlayer->GetPawn() == NULL)
    {
        NewPlayer->FailedToSpawnPawn();
    }
    else
    {
        // initialize and start it up
        InitStartSpot(StartSpot, NewPlayer);
 
        // @todo: this was related to speedhack code, which is disabled.
        /*
        if ( NewPlayer->GetAPlayerController() )
        {
            NewPlayer->GetAPlayerController()->TimeMargin = -0.1f;
        }
        */
        NewPlayer->Possess(NewPlayer->GetPawn());
 
        // If the Pawn is destroyed as part of possession we have to abort
        if (NewPlayer->GetPawn() == nullptr)
        {
            NewPlayer->FailedToSpawnPawn();
        }
        else
        {
            // set initial control rotation to player start's rotation
            NewPlayer->ClientSetRotation(NewPlayer->GetPawn()->GetActorRotation(), true);
 
            FRotator NewControllerRot = StartSpot->GetActorRotation();
            NewControllerRot.[Roll](API\Runtime\Core\Math\FRotator\Roll) = 0.f;
            NewPlayer->SetControlRotation( NewControllerRot );
 
            SetPlayerDefaults(NewPlayer->GetPawn());
        }
    }
 
#if !UE_WITH_PHYSICS
    if (NewPlayer->GetPawn() != NULL)
    {
        UCharacterMovementComponent* CharacterMovement = Cast<UCharacterMovementComponent>(NewPlayer->GetPawn()->GetMovementComponent());
        if (CharacterMovement)
        {
            CharacterMovement->[bCheatFlying](API\Runtime\Engine\GameFramework\UCharacterMovementComponent\bCheatFlying) = true;
            CharacterMovement->SetMovementMode(MOVE_Flying);
        }
    }
#endif
}

But I have some compilation errors:

  • ‘AGameMode::RestartPlayer’ : inconsistent dll linkage
  • use of undefined type ‘APlayerState’

Which includes do I need in MyGameMode.h and MyGameMode.cpp to solve this error? (sorry to ask such a basic question, I’m new to unreal engine)