Execution order Between GameMode Controller and Pawn

Hi, everyone.

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.

Feel free to ask if i’m not clear enough.

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.

hth :slight_smile: Marooney

So i tried and it’s even worse when i put a delay in the PC or the gamemode, i end up with every pawn having the default color. :frowning:

Here my quick reproduced and narrowed down issue I think you are talking about:

Run as Host:

LogBlueprintUserMessages: [MyPlayerController_C_0] Server: false
LogBlueprintUserMessages: [MyGameMode_C_0] Server: GameMode Set TestVar
LogBlueprintUserMessages: [MyPlayerController_C_1] Server: true
LogBlueprintUserMessages: [MyPlayerController_C_2] Server: true

Run as Dedicated:

LogBlueprintUserMessages: [MyGameMode_C_0] Server: GameMode Set TestVar
LogBlueprintUserMessages: [MyPlayerController_C_0] Server: true
LogBlueprintUserMessages: [MyPlayerController_C_1] Server: true
LogBlueprintUserMessages: [MyPlayerController_C_2] Server: true

What I mean:

Host & Dedicated:

LogBlueprintUserMessages: [MyGameMode_C_0] Server: GameMode Set TestVar
LogBlueprintUserMessages: [MyPlayerController_C_0] Server: true
LogBlueprintUserMessages: [MyPlayerController_C_1] Server: true
LogBlueprintUserMessages: [MyPlayerController_C_2] Server: true

Are you using constructors instead of EventBeginPlay that probably messes things up?

I’m sorry i didn’t provided any image to the topic. So to answer no i didn’t use the contructor here is what my BP looks like

ActorColor
Just and actor with 2 variable
Bool isAvailiable
LinearColor color

GameMode

PlayerController

Pawn

So if i resume in that state it works but not for the hosting player.

(Got some comment post issue so here we go:)

Ok I see, so your issue behaves like this: PC for server does not get the changed bool, and therefor the Pawn neither:

LogBlueprintUserMessages: [MyPawn_C_0] Server: false
LogBlueprintUserMessages: [MyPlayerController_C_0] Server: false
LogBlueprintUserMessages: [MyGameMode_C_0] Server: GameMode Set Var
LogBlueprintUserMessages: [MyPlayerController_C_1] Server: true
LogBlueprintUserMessages: [MyPawn_C_1] Server: true
LogBlueprintUserMessages: [MyPlayerController_C_2] Server: true
LogBlueprintUserMessages: [MyPawn_C_2] Server: true

When you put a Delay into the PC then your Pawns will be possessed before the PC takes the Color from the GameMode:

LogBlueprintUserMessages: [MyPawn_C_0] Server: false
LogBlueprintUserMessages: [MyGameMode_C_0] Server: GameMode Set Var
LogBlueprintUserMessages: [MyPlayerController_C_0] Server: true
LogBlueprintUserMessages: [MyPawn_C_1] Server: false
LogBlueprintUserMessages: [MyPawn_C_2] Server: false
LogBlueprintUserMessages: [MyPlayerController_C_1] Server: true
LogBlueprintUserMessages: [MyPlayerController_C_2] Server: true

Therefore the execution of the pawn needs to be reordered as well (i put 0.3 in there):

LogBlueprintUserMessages: [MyGameMode_C_0] Server: GameMode Set Var
LogBlueprintUserMessages: [MyPlayerController_C_0] Server: true
LogBlueprintUserMessages: [MyPawn_C_0] Server: true
LogBlueprintUserMessages: [MyPlayerController_C_1] Server: true
LogBlueprintUserMessages: [MyPlayerController_C_2] Server: true
LogBlueprintUserMessages: [MyPawn_C_1] Server: true
LogBlueprintUserMessages: [MyPawn_C_2] Server: true

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)

I hope that helps :slight_smile:

Btw. the PC for that (taking variable from GameMode and set it in PC to provide it further on to the pawn)

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

Thanks for the help !