Hi there!
I’m facing the problem I can’t figure out for a few days. In my game Pawn (VRPawn & AIPawn) contains UMilitaryStation component. This component is responsible for spawning an Actor AMilitaryStation. To determinate position of the stations I have my own class ASpawnPointStation.
ASpawnPointStation has just visual representation and int32 index; and bool bIsOccupied; variables.
In my map I have two Instances of ASpawnPointStation.
The goal which I want to achieve is, that each player (VRPawn, AIPawn) spawn it’s Station on different ASpawnPointStation.
UMilitaryStation component calls in BeginPlay this function:
void UMilitaryStationComponent::SetSpawnPointForStation()
{
SpawnPointForMilitaryStation = nullptr;
UWorld* World = GetWorld();
if (!World)
{
SetSpawnPointForStation();
}
for (TActorIterator<ASpawnPointStation> It(GetWorld()); It; ++It)
{
ASpawnPointStation* SpawnPointStation = *It;
if (!SpawnPointStation)
{
GEngine->AddOnScreenDebugMessage(1, 10.f, FColor::Green, TEXT("MilitaryStationComponent: !SpawnPointStation"));
UE_LOG(LogTemp, Warning, TEXT("MilitaryStationComponent: !SpawnPointStation"))
}
AllSpawnPointsStation.Add(SpawnPointStation);
}
Algo::Sort(AllSpawnPointsStation, [](const ASpawnPointStation* A, const ASpawnPointStation* B) {
return A->index < B->index;
});
if (AllSpawnPointsStation.Num() > 0)
{
for (ASpawnPointStation* SpawnPoint : AllSpawnPointsStation)
{
if (!SpawnPoint->bIsOccupied)
{
SpawnPointForMilitaryStation = SpawnPoint;
SpawnPoint->bIsOccupied = true;
SpawnMilitaryStation(OwningPawn);
return;
}
}
}
else
{
GEngine->AddOnScreenDebugMessage(1, 10.f, FColor::Green, TEXT("MilitaryStationComponent: AllSpawnPointsStation.Num() < 0!!!!"));
UE_LOG(LogTemp, Warning, TEXT("MilitaryStationComponent: AllSpawnPointsStation.Num() < 0"))
}
}
This triggers SpawnMilitaryStation if non Occupied SpawnPoint is found.
In SpawnMilitaryStation i call:
FVector SpawnLocation = SpawnPointForMilitaryStation->GetActorLocation();
FRotator SpawnRotation = SpawnPointForMilitaryStation->GetActorRotation();
The problem is:
It works in Editor as I suppose!
It works well when i go thru each step in Rider.
It works well When I run game as “Standalone Game”
IT DOESN’T WORK IN BUILD!
When I build the game or run with Project Launcher, one of the player founds Spawn point correctly.
Second one always spawns Station at 0,0,0.
I’m missing something and I can’t figure it out! Any ideas.
Btw it is single player. I’ve also tried offset function with delay, call it form different actors, with different events, but the result was still same.
I’m on 5.5.1 currently.