Can someone please explain to me the order in which things are initialized? I did some research and what I concluded was the below initialization order. But please correct me if I’m wrong.
Note: I’m using Unreal Engine 5.4 with blueprints, dedicated server Netmode = RunAsClient. With only 1 client right now.
My current understanding as to the Order in which things are initialized:
- GameMode (server)
- GameState (server)
- PlayerController (server + client)
- PlayerState (server + client)
- Pawn (server + client)
- HUD (client)
- GameState (client)
Note: It seems like the GameState on the server spawns first, then when the client connects the gamestate on the client spawns later?
So in my game, I’m needing to access things form various places, so I make reference pointers where needed. For example: from the BP_GameState, I need to access my BP_PlayerController so I stored a variable reference. And from the GameMode I need to access BP_GameState, so i stored a variable reference. From my BP_PlayerPawn I needed to access BP_PlayerController, so I stored a variable reference.
There were some interesting initialization orders, so in some cases I had to make some event dispatchers to go back and set reference variables when that BP was finally initialized.
This is the issue I ran into today. My server spawned a BP_GameState, which is great, but I need access to my BP_PlayerController and it’s currently null. So maybe that means the player hasn’t connected to the server yet?? So I’ll need an event dispatcher to go back and update the variable once the player connects?
So my question really is. What is the order in which things actually load? And how do you guys keep communication between components open? Am I going about it correctly by storing reference variables? And am I correct in sometimes I have to make event dispatchers to backtrack and update a reference variable when something finally initializes? Or is this hacky hocus pocus and there’s a much better way?
My project maps and modes in case this is helpful.
Bonus question: If my server stores a variable reference pointer to a blueprint (that is replicated) in my GameState (also replicated), is it safe to assume that the variable reference pointer will still work on both the client and server? Or do the client and server need separate reference variables?
Thank you!