Will I fully understand Replication someday?

I am working on multiplayer since 1Y+ and I achieve what I want and think I understand the whole concept about replication/multicast/run on server/repnotify, etc…but then sometimes things are not working and I start trying different approaches and then It works and I say aha! this is how it works and I am in that cycle forever…I never fully understand everything about replication and multiplayer.

Right now I want to run a multicast event from a widget event (lets say a key press).

If I do this on player controller:

image

and then from the widget I do this:

Is not working (I am pressing the key in the server/player)

BUT If Instead I do the multicast in GameState like this:

player controller:

gamestate:

image

it works.

I dont know what is the situation where runOnServer–>multicast works doing all inside player controller and when I need to do runOnServer(PlayerController)–>multicast(Gamestate)

Can someone explain? I am not looking for a solution here…just looking for answers and try to understand for once.

You should not use player controller. It is not spawned on the server.
Instead of GameMode use GameState, instead of PlayerController use Player State.

Try that one, and let me know how it works. I used it widely on my game, and every type of event replication worked consistently.

1 Like

That’s wrong, player contollers do exist on the server and their owning clients, but no one else

1 Like

thanks! will try :slight_smile:

ok, but if it EXISTS on the server, then why I cant invoke player controller and theb RUN ON SERVER — > MULTICAST ?

you say playercontroller exists on the server too.

You mean that the widget cant trigger it because is not owning client?

Because like I said, player controllers only exist on the server and their owning client, so a multicast won’t work as you want it to, since the other clients dont have your player controller, so the multicast will never reach them

1 Like

No they don’t . They were null on my game. Either I missed something really big, or I have developed my game in really wrong way :D. I used playerStates.

Player controller only spawns locally on the local player controller.

1 Like

that is actually wrong, I’m sorry, they exist on the server

in fact it’s the basis of all unreal’s multiplayer, since the player state is spawned for the player controller

1 Like

@zeaf is correct. PlayerControllers are Spawned by the Server but only relevant to the Owner and therefore any replication on playercontrollers only reach the owner.

2 Likes

Ah OK. Understood. This is why I had them as null then. It explains it. Anyways, we all agree, for replication stuff we should use PlayerState?
Sorry @zeaf

1 Like

wait wait…I feel a cannon moment for me here LOL
Does playerState ARE replicated on all other players? just like gamestate??

player states are spawned per player, and are replicated to all, yes

so all players know of other players’ player states, and they are always relevant

2 Likes

wow! If you see the game I am doing WITHOUT using playersState you would not belive :joy:

I will do some testings with playerstate and after this I think the no use of it is the 99% misery in my life since 1Y+ ago

Use PlayerState, and you should be good :). Sorry for confusion about spawning stuff. My bad.

1 Like

can you explain some rule about when multicasting on gamestate and when doing it on playerstate?

Rules are pretty much the same in every replicated component. It really depends on what do you need. Do you understand difference between Client, Server and Multicast?

1 Like

Here is more info on it: Replicating Functions in Blueprints | Unreal Engine 4.27 Documentation

1 Like

Yes I do. But I assumed as player controller lives in the server and the client then lives in all the others but now is clear all playercontrollers are replicated only on owners and server

1 Like

you just have to remember the point of both objects

A player state is meant to contain data and functionality specific to the player, whereas a gamestate is meant to be for the “game” itself

Each player has ownership over its own player state, which means they can call Server RPCs from it
The gamestate is owned by the server only, so no player can call Server RPCs on it (unless the server has a controller, which is the case for Listen Servers)

2 Likes

my missing piece was playerState and its Key…I am using playercontroller thinking it behaves like actually works playerstate