Multicast from client to everybody pattern?

Haya,
I’m trying to figure out if there’s a way to have an actor that is capable of receiving messages from a client and then multicasting then to all other clients somehow (thinking like a chat system). Essentially what I want to do is to have a client be able to trigger an event on all players in a game, but the only way I can see to do that is by using the client owned playerstate/playercontroller to route messages to some server side actor that then multicasts everything back down. I’m not a huge fan of this because it seems like it will clutter up my playerstates/playercontrollers over time as similar functionality is needed.

Ideally what I want is to be able to have a nice encapsulated system where clients can call things on the system that can optionally call things on the server/other clients depending on what’s needed. Right now it feels like way too much gets routed through my playercontrollers/playerstates and it feels icky to me.

The only way I can see to keep things actually encapsulated atm is to spawn a server actor, then when it spawns on the client have it spawn a client owned actor that it has a reference to, but that still feels awkward to me.

In order to be able to use a RPC method you need to be the owner of that actor.
I whould create some RPC method called by client executed by server e.g: SendChatMessage(FString);

Server side a NetMulticas RPC is called triggering a delegate event witch is picked up in UI to display the new message for all clients.

Hope it clear some stuff up.

If you want to run RunOnServer RPCs (Client->Server) you NEED a client owned Actor. Even if you dislike that, you will have to go other the PlayerController, PlayerPawn, etc.
to actually reach the Server. Once you’ve done this, you can multicast back to the clients.

What i’ve done to maintain order and structure in my PlayerController, even with tons of replication logic, is to create my own Components for the different things i’m doing and add them to the PC.
Then the code is split off and i can still use Client->Server RPCs.

1 Like