So have trouble figuring out why the pawn controlled by the host (Understand server host) is not initialized at the same time as client.
So here is my chain of events.
GAMEMODE : Generate 4 colorActor (wich contain 2 variable, Color, and isAvailable) and store them in an array.
MYCONTROLLER : Sets a default color then Loop through the Gamemode Color Array, if a color is available, the player Controller store it in his PlayerColor variable (removing the default value) and set isAvailable to False and break. If not available then the loop continues to attribute the next color.
PAWN : OnPossessed event, it grabs the color set by the PC and apply it as a texture.
Ok so far so good everything works BUT ONLY for the clients. The player being the Host keep the default color set in my Controller class.
It’s like the PC and the pawn are created before the gamemode. please help.
Hi there, if I experience such execution order issues, I just put a Delay in (is probably what everyone does as far as i have seen in streams or so).
Might seem quick and dirty if you think about race conditions, but a Delay just queues execution and does not execute in parallel.
In your case you probably need to put a Delay in the PC when selecting the color.
Well this is the situation where i tend to assign vars in a different way to avoid messing around with too many delays: E.g. Pawn fetches color directly from the GameMode itself (Sticking PC EventBeginPlay nodes into Pawn EventBeginPlay nodes, if possible).
Some refactoring:
If other players need to see the color of other players in visual representations (HUD or so), you can handle the player color in the PlayerState of the player which everyone can see.
Since only the Server has the GameMode, there is no reason to replicate things in there (like your ColorTable).
I am not sure how you deal with your ColorActors since actors need to be spawned within the level. If you just need to hold 2 Variables you can use an Object instead. (Or structs if there was no value change)
Ok i found out what was the problem and it’s so stupid.
When you launch the game from the editor it creates a defautPawn at your camera location as part of the level. THEN and only Then attach the pawn. So yeah i implemented a basic respawn and everything works well