PlayerController ownership behaves inconsistent

Hey folks,

i try to replicate an event from the playercontroller to the server. However on of the two clients does not own its own PlayerController so the event never gets replicated. On the other client the ownership is set correctly (even tho i never set it anywhere). How can i set the owner to the client? I tried branching off with a “Is Local PlayerController” and setting the ownership there but it never gets set :frowning:

Any ideas?

Clients do own their own PlayerController.

There has to be something wrong with your usage :grimacing:

Do you maybe have an idea where i could be wrong? Some mistake that is often been made? is the method i check for authority correct? Currently i tried a multicast to set a boolean im my HUD with an “has authority” node before.

:smiling_face_with_tear:

HUD only exists on clients. Each player has its own HUD and there is no replication between them/server.

The only situation where HUD might have Authority is for the host of a listen server, because the host is client and server at the same time. Even then, the host’s HUD only exists for the host and does not replicate to other clients, so multicast basically has no effect.

Maybe if you show what you’re trying to do we can help put things in the right place.

1 Like

Ok lets dig deeper into this. First of all the reason i think the playercontroller does not own himself and then the thing i originally wanted to archive. I use a dedicated server with 2 clients that connect to it. Client 1 created a session and client 2 joined.

  1. PlayerController does not own himself?

I create HUDS in the PlayerController and call an event (“replicated to owning client”) that sets the PlayerControllers owner in a text. The HUD is also owned by the PlayerController.


The result:

On both clients the given PlayerController Owner seems to be noone (" ") but getting the owner in the hud returns the PlayerController. Why it seems like the PlayerController has no owner?

  1. Spawning an actor with the players name attached and display it in a HUD text

The thing i wanted to do is pretty basic: Just spawn a Unit for a player when the player presses the “c” key. Replicate to PlayerState on server to spawn the unit there. Get the playername and set it on spawn. In the “begin play” of the spawned Unit sets the name when creating the HUD (“exsposed on spawn”).

PlayerController:

PlayerState:

Result (the same on BOTH clients):

Note: The color (also set in the PlayerState) is correctly replicated but the player name is not (look the error message on the red unit aka the 2 clients unit)

I guess i just replicate the name wrong or maybe a have to set the name with an event? If so how do i get the name of the right player (on server) into a hud on every client (local) ?

I hope the BP are readable if not pls let me now. They are quite mess because i tried A LOT of things by now but it feels like iam missing something.

Best regards and thanks!

M

Regarding point 1, PlayerControllers do not have any Owner. They are the root owner. When an actor checks for owner replication, it looks for a PlayerController in its chain of owners.

Clients are only aware of their own player controller. Other clients controllers do not even exist.
If you have 3 players on a server, the server will have 3 player controllers. But each client will have only one (his own) playercontroller, connected to the corresponding one on server side.

Regarding point 2 :

  • Being in PlayerController, the variable “My Player State Ref” is redundant. PlayerController already has a (properly replicated) way to access its associated player state.

  • Being in PlayerController, you can call a server RPC directly there. No need to go through PlayerState.

  • Looks like you’re using a custom PlayerName variable instead of the builtin engine one. If you are getting correct results regarding the spawned actor location, rotation, color, team, but the name is wrong, then chances are you messed up something with name replication. Considering other variables (color,team…) are coming from client through SpawnUnit, but PlayerName does not, I suspect there’s an issue with properly setting your variables on server side.

Hello,

point 1 makes sense for me thank you clearing that up! Spawning the actors works fine now by passing the playername from the PlayerController. However now i got the same problem with an other actor (clients show different behavior):

Every player has an 3D cursor that should be replicated to teammates (replicated to all players for now to make things easier). The code an replication was exactly the same as the one that spawns the actors before. But again both clients showed different behaviours.
Client 1: sets the location of BOTH clients 3d-cursors
Client 2: sets only this own 3d-cursors (right behavior)

I now tried every possible combination of replication events in PlayerController and PlayerState but every time something is off.
I ended up with this code:

Begin Play PlayerController:

EventTick PlayerController:
opticRep6

PlayerState:

The result now: Client 1 shows only his own 3dcursor. Client 2 shows both 3dcursors correctly (on the right position).
Client 1 (blue cursor) / Client 2 (red cursor)

Looks to me like the 3dcursor of client 2 is not replicated but the one of client 1 is… why? The 3dcursor is fully replicated. If i call “SpawnOpticCursor” with “execute on server” client 1 sets the position of both players … What am i missing? Why do both clients behave differently?

EDIT: I now call the spawning and location setting “on server”. Now 3 optic cursors are spawned even tho i only have 2 (owning) clients ?!?

EDIT 2: I now printed the results of “is dedicated server” and “is server” on BeginPlay of every PlayerController. The result: Client 2 returns false for both but client 1 returns “true” for “is server”. How on earth and why?? I start with “Play as client” and not a listen server so why does the first client become the server??

EDIT 3: Client 1 actually becomes the server because he hosts the advanced session. Looks like you cannot create an advanced session on a dedicated server. Marking this post as resolved because the two clients are actually a server and a client and therefore do not share the same behaviour.