Multicast event doesn't run on client

Hi! I’m new to multiplayer so I’m trying to learn on a small project first (a simple tic tac toe game).
I’m trying to spawn a decal after each move (for everyone).
The problem is when I try to call the Event (set on multicast)from the server, it runs on the server but not on the client, but it works perfectly fine if it is called from the client.
Here are the blueprints:

(Red = Client, yellow = server)

Hi, Multicast won’t work as you expect with player controllers. All player controller exist on the server, but on each client only one player controller exists, the player controller of that client.

Therefore if the server would call a Multicast on the player controller of the server, then only the server will execute it (since this player controller does not exist on any client) and if the server calls a Multicast on a client controlled player controller, then it will execute on the server and on that client, but not on any of the other clients.

Therefore you would need to put this logic into a different actor that exists on all clients.

6 Likes

Thank you. That was really helpful.
One more question: Should I make a new replicated actor just for that or should I put it into GameState?
GameState is shared by all of them, (right?) but It doesn’t execute the same thing if its from client.

Should I make a new replicated actor
just for that or should I put it into
GameState?

It doesn’t really matter, since both will exist on all clients and replicate. You could read this to get a better feeling of what you generally put into the GameState Game Mode and Game State in Unreal Engine | Unreal Engine 5.3 Documentation

GameState is shared by all of them,
(right?)

Yes

but It doesn’t execute the same thing
if its from client.

Not quite sure I understand what you mean =)

If a client calls a Multicast, then only this client will execute it. All the other clients and the server will not.

I feel like my explanation wasn’t good enough…
I want the client to call this event on the server:

316739-1.jpg

Which calls this multicast ON SERVER:

So a decal should spawn on Clients and Server.

But the end result is the red decal never spawns:

Is there a flaw in my approach?

Yeah that won’t work. The only client that can call a Multicast on an actor is the client that owns that actor. Idk if a client can own the GameState, never tried that…

Generally inside the player controller (which is owned by the client that controls it) you would directly replicate the player input of the client to the server (RunOnServer) and then continue on the server. Then use replication to send the relevant information to the clients.

Or if you know that there is only ever going to be one client that calls RunOnServer events on an actor, then you can set that client as owner of the actor and then also do it there.

Alright, I’m gonna share the blueprint for the people with the same problem.
In my case I used gameState to track “State Of The Game!” and whenever I needed to execute some lines for both client and server, I used this:

On the Server there is no problem calling an event with Multicast.
But since the Client doesn’t own the gameState it needs to get an Event that “Runs on server” to do the job instead.
In my case I used an event on player controller since it exists on the server

So if you’re running ANY multicast event, it needs to exist inside the GameState? That sounds really weird.

So if you’re running ANY multicast event, it needs to exist inside the GameState?

No. The issue here was that the multicast was inside the player controller and the player controller only exists on the server (and the client this player controller is associated with), but the code should execute on all clients. Therefore the solution there was to put the multicast into an actor that exists on all clients, so that the multicast executes on all clients.
The GameState just happens to exist on all clients, but you can just create a new actor, mark it to replicate and spawn it on the server and then have the multicast there.

1 Like

Over a week of struggling to replicate actor clicked events through the player controller eventually i found this post and said ■■■■ it ill put it inside the player character. You have absolutely no idea how big my smile was. Thankyou :slight_smile: