- Home /
How to give a client authority over an object in UNET?
How would i go about doing this? NetworkIdentity.hasAuthority and NetworkIdentity.playerControllerId are both read only and NetworkIdentity.localPlayerAuthority's doc says that "LocalPlayerAuthority means that the client of the "owning" player has authority over their own player object." but i don't know how to have a player own an object
Answer by nisovin · Jul 28, 2015 at 04:50 PM
These pages of the documentation talks extensively about player objects in UNet, including how to spawn them:
http://docs.unity3d.com/Manual/UNetManager.html
http://docs.unity3d.com/Manual/UNetPlayers.html
Keep in mind in the current version of Unity you can only have one object with authority per player in the game, and that's the player object.
the links were very helpfull, i kept looking for something to define the owner like in the previous networking system without realizing there were special objects for that now. but any way to prevent confusion here is a quote from the docs about having multiple player objects per client.
"In most cases there is a single player for each client. But, in some situations - such as when there are multiple controllers connected to a console system, they could be multiple player objects for a single connection. When there are multiple players for a connection, the playerControllerId property is used to tell them apart. This is an identifier that is scoped to the connection - so that it literally maps to the id of the controller associated with the player on that client."
As stated in my answer, as of Unity 5.2 you are now able to give clients authority over non-player objects. See: http://docs.unity3d.com/$$anonymous$$anual/UNetConcepts.html
Answer by Jason-H · Oct 01, 2015 at 01:00 PM
As of Unity 5.2 we are able to give clients authority over non-player objects.
See the section titled "Client Authority for Non-Player Objects" here: http://docs.unity3d.com/Manual/UNetConcepts.html
Answer by grandmapuckett · Jul 28, 2015 at 06:23 PM
Are you making a game that involves the concept of controlling game pieces? Like units in an RTS, or players in a party on a RPG, or what have you?
If so, i had the same problem, and not knowing any better, i made my own simple system: in the game, every object that can be controlled by a player has a string variable "Owner" that gets filled when that object is created with the name (or identifier, or what have you) of whatever player or game entity is requesting its creation.
You can make that string a Syncvar, so that the owner string of that piece is the same on all clients,and then you can play around with it, so for example, on each client you could check who is your local player, then check a game piece's owner: if the owner string matches the local player, that game piece is a friend on that client, otherwise it's an enemy. You could use the same check to allow that piece's function to be called (or not) by a given player.
It's crude, and I bet there are more elegant solutions around, but this works for me. Hope that helps or at least gives you some ideas.
UNET makes it so that even if the client knows that it is meant to control an object it can't send RPCs to the server unless the client owns that object so that solution wouldn't work unfortunately :(
Due to Commands and ClientRPCs not being usable outside of player objects? Bummer. I don't understand why Unet kinda implies that the only objects that can talk to their server counterparts and viceversa are just player objects.
In an RTS, the client doesn't have authority over its units. The player controller object itself send commands to the server telling the server what it wants to do with those units (move, attack, etc). The server then realises these actions and tells the client what happened.
It is not the client's responsibility to simulate the position of the units or anything else; this is how all professional RTS games are designed. Anything less would be potentially exploitable or otherwise unstable.
This is actually a quesion I have myself. How would one implement an RTS in Unet? I don't want to give my client authority over the actual units. I just want the client to send his input to the server and let the server handle all objects.
Your answer
Follow this Question
Related Questions
UNET NetworkServer.Spawn intermittently not called on clients 1 Answer
Unity networking tutorial? 6 Answers
Local IP adress in UNet 4 Answers