I probably have a fundamental misconception of UNET, so please excuse the newbie-ness.
I want to send each players webcam video update in a multiplayer setting. This is quite different from the standard multiplayer input system, wherein the solution is:
if (isLocalPlayer) {
// simulate the result of the keypress locally and send a command to the server for validation and
// broadcasting this via client rpc to other clients
ProcessKeyInput(...);
CmdSendKeyInput(...);
}
else {
// do nothing
}
[Command]
void CmdSendKeyInput(...)
{
RpcProcessKeyInput(...);
}
[ClientRpc]
void RpcProcessKeyInput(...)
{
if (!isLocalPlayer)
ProcessKeyInput(...);
}
Bump. I’m looking into MessageBase and custom messages as a possible solution for this, and I don’t quite understand if I would need to do the routing/dispatching of various messages received to the appropriate game objects.
Have a custom message type for video updates and a VideoMessage class that inherits from MessageBase.
I can override the OnSerialize and OnDeserialize methods to construct/deconstruct the message
Sending/receiving these messages seems to require classes overriding NetworkServer and NetworkClient. I’m using a NetworkManager currently, and don’t know if I can use these server and client classes in conjunction with the manager.
The client message handler needs to know which player originated the message, and thus, learn about players joining/leaving the game. Can the client register for the message types specified in RegisterHandler?
Thanks. It’s a useful Message passing reference, but I’m really interested in understanding what the correct/best approach is for my problem. Let me try to summarize:
Problem: I want to synchronize the webcam texture images of players in a networked multiplayer setting.
Solution 1: Use network messages to send texture updates to server, which broadcasts to all clients (similar to the chat system). This requires a client message handler to receive not only the video update message, but also player connect/disconnect messages to display only the currently active players. In addition, each client needs a unique playerId (another network message at client connection time). On receiving the video update message (with player id), the corresponding player’s texture is updated.
While this seems ok, it feels like a lot of relay from the server to the client to mimic current state and feels a little global in nature, i.e., a script owns all the textures of all the players (sometimes this is nice, I’m not sure in this case)
Solution 2: Spawn another prefab per player that has a NetworkBehavior component with a texture. Override the OnSerialize and OnDeserialize methods. If there was a way for the client object to send the server the texture update in a local fashion, i.e. not a global network message with netId and then have the server FindLocalObject and update the texture data on the server (which would then, I assume be serialized and sent to all the clients), I wouldn’t need to do message handling on the client. It’d all just work beautifully with the UNET framework.
I hope some of this makes sense. I might be completely mistaken, but I’m really just trying to understand the cleanest/right solution.