[UNET HLAPI] Broadcasting info from server class to a different class in all clients

Hello everyone,

I have a class (ServerManager) that has a NetworkIdentity component and in that component I selected “Server Only”, and another different class (ClientInstance) also with a NetworkIdentity component but this one has “Local Player Authority” selected.

If I wanted to share attributes from class ClientInstance between the Client and the Server all I had to do was add [SyncVar] to that attribute and the Server would be able to propagate those changes to all Clients. Now imagine my ServerManager has an attribute that needs to be used by all ClientInstances. How would I be able communicate with that class in all clients using HLAPI?

Hopefully someone can clear this up for me.

why do you have the SM as server only? Why not uncheck that box, and have the SM class/instance be available on both Server and Clients, then you just use SyncVar’s or RPCs from the Server side of the SM to the Client side of the SM, to pass data/infos… For getting info from an authoritative client to the server, you’d use a Command (CMD) to get the value to the server, then syncvar or RPC to distribute it back to the other non-authoritative clients. The server CI could also talk to the Server SM instance, if you needed to get info to it. This is all a bit hand-wavy as i don’t really understand or know your architecture or what you are trying to do…

Your solution is the one I was going to implement but I got in my head the idea that it is not an elegant one, so I decided to try and fix that. The value that needs to be synced is a seed that is defined OnServerStart and it’s going to be used for generating a height map. The CIs use the same seed every time it needs to generate the same map tile, but the seed is the same. It remains unchanged throughout the game and the each client only needs it once OnStartLocalPlayer.

Ultimately I’m gonna use the solution you provided, and I’m not going to dwell on code elegance as it can be anti-productivity (also it is sometimes very personal and maybe nobody else would consider my solution as elegant anyway).

I appreciate you taking your time to answer my question, but I would still like to know how to achieve the solution I was searching for, even if just out of curiosity.

I still don’t really understand what it is you are trying to achieve or the overall “look” of your architecture. I am generally pretty pragmatic about these things, and try to work the way Unity wants you to work, as I understand it, because it causes far fewer programming headaches. Reading the HLAPI UNET source has been extremely helpful in figuring out how they expect you to work with their components.

Good luck!