Hi, I am working on multiplayer project and I need position of all players for logic. I have my specific actor for them so I know getting all actors of that type is one option, but I dont think it is good one, because I need it to be dynamic (player leaves/joins, it updates automatically) and it is highly likely I´ll be working with the positions every frame so that may be another problem.
Try using FConstPlayerControllerIteratorFConstPlayerIterator to cycle through all player controlled players and get the location of their ControlledPawn(), if any.
I use gamemodebase as well and I did try what youre describing, but I ended up with my players starting with spectator actor instead of my own custom actor which I couldnt fix.
Make sure you call the parent method via Super:: in your overriden method especially in PostLogin as that calls RestartPlayer which I had to override (and NOT call the engine’s method) so that I could use AdjustIfPossibleButAlwaysSpawn as my spawn parameter. I then had to copy some of the engines RestartPlayer functionality into my method and assign the pawn to the controller.
Do the additional clients/windows show the same custom pawn? I would expect that if you hardcoded the pawn class in RestartPlayer.
I override “GetDefaultPawnClassForController_Implementation” (called in RestartPlayer before the SpawnActor call) and have a setting on the playercontroller that indicates which pawn to use.
They do not, only the main (first) client spawns as the custom pawn. Also I do not understand what you mean by RestartPlayer. All I have done is set DefaultPawnClass.
LogSpawn: Warning: SpawnActor failed because of collision at the spawn location [X=0.000 Y=0.000 Z=0.000] for [Vessel]
LogGameMode: Warning: SpawnDefaultPawnAtTransform: Couldn’t spawn Pawn of type Vessel at Rotation: Pitch 0.000000 Yaw 0.000000 Roll 0.000000
Is it possible that the first pawn blocks the rest from spawning? If so how can I fix this?
That error is the reason I overrode the GameModeBase’s RestartPlayer method so that I could specify the parameter the the SpawnActor call to always spawn. Well, and to be able to specify the location of where the player is going to spawn.
Ye I get that, but what did you modify in the function, you said you “specified parameters of the SpawnActor call to allways spawn”. Thats what I do not understand/want to specifically know how.
FActorSpawnParameters SpawnParameters;
**SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;**
auto HeroClass = GetDefaultPawnClassForController(NewPlayer);
if (x != 0 && y != 0 && z != 0)
{
m_Hero = GetWorld()->SpawnActor<AAWPlayerCharacter>(HeroClass, loc
, SpawnRotation, SpawnParameters);
}
if (!m_Hero)
{
AActor* StartSpot = FindPlayerStart(NewPlayer);
SpawnRotation = StartSpot->GetActorRotation();
m_Hero = GetWorld()->SpawnActor<AAWPlayerCharacter>(HeroClass, StartSpot->GetActorLocation()
, SpawnRotation, SpawnParameters);
}
Also, I saw in your earlier post your location and rotation are all zero, origin. I doubt that you are wanting to spawn there, unless your level is perfectly flat, I guess it is possible.
Thanks for explaining! By the way I fixed my issue with pawns blocking the rest of pawns from spawning by setting my PlayerStart to allways spawn. Stupid problem to begin with but I guess I learned that at least.