In a multiplayer scenario, on host side a GameMode is created and he is the owner of it alone. Then a GameState, Controller, PlayerState, Pawn is created for the host. When a new player joins the session, the host GameMode creates a GameState, Controller, PlayerState, Pawn for the player.
While the creation of these elements takes place, inside the Controller you have the node Is Local Controller (or Is Local Player Controller if you need more specific type of controller) which you can use to tell if the code is executed on host, or on client.
While this is great, are there similar nodes for GameState, PlayerState and Pawn? Or if there isn’t a simple Is Local X node, then can you tell me a way to tell if it is on host or client side?
I need to do some calls/changes inside them when they are first received and Construction Script and BeginPlay are called.
To distinguish between host or client side you should use the Authority/Remote switch.
IsLocallyControlled is used for more fine-grained control, but doesn’t tell you if you are on server or client. It is generally used with prediction mechanisms to filter out after a multicast and avoid doing something twice on the instigator machine.
When it is on client side, it is printing “Client” but the value for “Nickname” remains the one set by the host, and it isn’t updated to the client one. I tried to make “Nickname” replicated but still not working, also being a value inside PlayerState, shouldn’t be replicated anyway?
//Edit1:
Solution that I came up with, don’t know if it is the best, but it gets the job done (same blueprint PlayerState):
“Host” nickname is set somewhere else. If I do the same for host inside “Authority”, the code will be ran for each player when it creates PlayerState for them, and will set the wrong value each time, as it will set “Host nickname”, so in my opinion that code if it is ran there is a waste.
At first I thought that code ran in PlayerState will update values locally, then send to server, which in turn will send to everyone else, but it seems that is not the case.
In this specific case you want each controlling player to send his own nickname to the server, so IsLocallyControlled makes sense here. You don’t need to check if you are on server or not. Run on server will execute even if you are already on server (host).
For PlayerState it is not directly available, but a player state is owned by its player controller. So you could do GetOwner → Cast to PlayerController → IsLocallyControlled → Update Nickname