I’m having an issue where I cannot use PlayerArray in a static function… I’m sure this is by design but I can’t figure out a way around it. What I’m trying to do is specifically transform the player to the location of the playerstarts when the game begins. The playerstarts have their tags set
AMyGameState.h
UCLASS()
class CCREATURESONLINE_API ACCOCardGameState : public AGameState
{
GENERATED_BODY()
public:
static int32 getPlayerIndex(APlayerState* playerHolder);
};
AMyGameState.cpp
int32 ACCOCardGameState::getPlayerIndex(APlayerState* playerHolder)
{
int32 index = PlayerArray.Find(playerHolder);
return index;
}
AMyPlayerState.h
UCLASS()
class CCREATURESONLINE_API ACCOCardPlayerState : public APlayerState
{
GENERATED_BODY()
TArray<APlayerStart*> playerStarts;
APlayerStart *PlayerOne;
APlayerStart *PlayerTwo;
APlayerStart *Spectator;
void BeginPlay();
};
AMyPlayerState.cpp
void ACCOCardPlayerState::BeginPlay()
{
for (TActorIterator<APlayerStart> ActorItr(GetWorld()); ActorItr; ++ActorItr)
{
playerStarts.Push(*ActorItr);
};
for (int32 itr; itr < 3; itr++)
{
if (playerStarts[itr]->ActorHasTag("Player1")) PlayerOne = playerStarts[itr];
if (playerStarts[itr]->ActorHasTag("Player2")) PlayerTwo = playerStarts[itr];
if (playerStarts[itr]->ActorHasTag("Spectator")) Spectator = playerStarts[itr];
};
int32 index = ACCOCardGameState::getPlayerIndex(this);
if (index == 0)
{
SetActorRelativeTransform(PlayerOne->GetTransform());
SetActorRelativeRotation(PlayerOne->GetActorRotation());
};
if (index == 1)
{
SetActorRelativeTransform(PlayerTwo->GetTransform());
SetActorRelativeRotation(PlayerTwo->GetActorRotation());
};
if (index == 2)
{
SetActorRelativeTransform(Spectator->GetTransform());
SetActorRelativeRotation(Spectator->GetActorRotation());
};
}