Am I Server or Client?

anonymous_user_b220333c
Sun, 01 Mar 2020 00:47:56 +0000
Multiplayer & Networking

I am starting to go crazy trying to check if the current instance of the game is the server or the client. According to all documentation and tutorials I can find there are two ways to check if you are the server or the client. 1. Role == Role_Authority. 2. HasAuthority().

From the tests I have been doing it does not seem like those two checks are actually checking if the instance of the game is running on the sever or client but seems more like it is checking if the actor that is calling it is possessed by itself or a player controller.

How the test I am doing works - below

I have created an actor that in the beginplay() function in its class does the if(Role == Role_Authority){ log “I have authority”}. This actor is placed in the level at runtime and is not spawned in after runtime. The actor has replicate checked as true.

Presumably from what ue docs say, this actor should only log “I have authority” on the server… Right? But it logs it on the clients AND the server as if every instance of the game has authority over this object.

So I thought to myself that maybe it is because it has the “Net load on client” checked as true so this is making it spawn on the client and the server and for some reason this gives the client authority… to test this I made the “Net load on client” == false. This is where my brain almost exploded… When the game boots up the actor no longer spawns on the client (or atleast does not render) but somehow it still logs “I have authority” on both the client AND the server. How is this possible if the actor is not even supposed to exist on the client???

I repeated the same test using HasAuthority() and get the exact same results.

Now the next thing which is what makes me believe that these checks actually are checking possession is if I make a client player possess the actor that is logging “I have Authority” in beginplay() and put a if(hasAuthority) or Role == Role_Authority then log “I have authority” else log “I don’t have authority”, it logs “I DONT have authority”. So when it is not possessed by a player it has authority but when it is possessed by a player it no longer has authority.

I did read that if a client spawns in an object then the client may have authority over that object. So I am trying to figure out how on earth do I make the server spawn in the object. The only way I can think of doing this is by checking if the instance of the game is the server and if it is then spawn in the object. But if hasauthority() does not actually check this then how do I do it???

9 posts - 6 participants