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:
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.
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.
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?
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.
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