Collection of Objects under One (Or Multiple) Owner(s)? (uNet)

I’m working on a little project that involves the ownership of land, buildings, and even units. Think of it a bit like an RTS. Try as I might, I haven’t successfully found any resources on connecting anything close to that nature to uNet or PUN (Currently using uNet and intend to stick with that), so I have a few questions about it:

First, how would one go about telling the project who owns what, and giving interesting controls only to the right people? While we’re at it, what about multiple owners of the same content?

Second, is the ‘ideal way’ of keeping track of ‘this’ player’s main character, buildings, etc, storing it locally on creation, or is there a better way to go about figuring that out? This leads into the question about utilizing mouse clicks on objects for the sake of controlling or otherwise interacting with objects on behalf of a particular selected character/unit/etc.

Pretty much just need help with the finer details of how ownership is determined and even changed from one person to another… and how to make something ownerless, while we’re at it.

Thanks!

If you have multiple owners for 1 object then [Command] will not work.

You can use UNET message to send information (for example you could send NetworkIdentity.id, vec3 move location). The server could then decide to accept/reject this message based on ownership. The server could also tell clients who are the owner(s)… unsure the best way on this one though (messages, rpc’s, a syncList of owners might be some things to try)
https://docs.unity3d.com/ScriptReference/Networking.MessageBase.html

Do you happen to have a link describing exactly how to use those? After hours of looking around, I’ve only found vague information pieces that don’t really give me the full picture on how to use them… or even how exactly to write a basic script to see it work.

Thanks! :slight_smile:

No link. But here’s a quick description.

Step 1: Create a new CustomMessage class that inherits from MessageBase. Any serialized information will be sent (just like mono serialized data).

Step 2: Register the message. I do this with a CustomNetworkManager during either OnStartClient/OnStartServer.

Messages sent from Client → Server need to be registered during OnStartServer
NetworkServer.RegisterHandler(msgType, SomeMethod);

Messages sent from Server → Client need to be registered during OnStartClient
networkClient.RegisterHandler(msgType, SomeMethod);

Step 3: Instantiate & Send Message

Hmm… so the… method gets sent to the opposite of what’s calling it? So, say I call a method that just changes a variable from the server, it’ll just change it on the client? What’s msgType?

Thanks! :slight_smile:

msgType is a ushort ID that is unique to this message. i.e. use MsgType.Highest + 1 for your 1st message, and +2 for your 2nd, etc.

Yeah if you want to send the server something
-Instantiate message on client
-Assign serialized data in the message instance on client
-Send the message to server
-Server reads message and invokes it’s associated registered readMessage method

and vise-versa for server → client

So basically keep an integer and increment it every time… does it have to be different every time even when you’re swapping between client and server calls?

I believe you can save the same number for client & server (there are 2 separate registries).

Then in your method that gets invoked you can use something like this.
CustomMessage customMessage = networkReader.ReadMessage();
customMessage.data…