who can move objects in multi-player games...

Hello everybody,

I am developing a virtual world where each object (prefab) is allocated using Network.Instantiate as I need to synch all the objects inbetween the clients. Now,
if ClientaA allocate a prefabA and moves it, well all the clients see it.
but if ClientB moves prefabA, well… the prefabA’s position is not updated is the other clients views.

I move each object using DragRigidBody.js available in Unity.

Thank you very much for any help.
GC :slight_smile:

"but if ClientB moves prefabA, well… the prefabA’s position is not updated is the other clients views. "
Thats because clientA owns the prefab. If you want all clients to be able to move all prefabs, make the server authorative, and have the clients send there commands to the server.

ouch…ok thanks… uhm. I guess this is little more advanced for me… any suggestion regarding what I look at as an example of authorative server?

Many thanks.
Gc

Theres one in this guide Networking Guide

It’s not too bad, but you just instantiate everything on the server or manually assign the NetworkViewID components. What we’re doing is sending a prefab and network IDs to each connected client who then instantiates the prefabs and the client sets up the NetworkView component. With that an reasonable OnSerialNetworkView() configurations, we’re doing OK.

Hmm, I have a question, then…

I currently have basic authoritative AI enemies set up in my game,simply by destroying the enemy spawn objects in all instances of the game except the server, and the server constantly checks if any of the players in the scene get within distance to the spawn object, and Network.Instantiates an enemy at that spawn.

In this situation, the server is the network owner of those enemies when they spawn, because he is the only person calling Network.Instantiate… so I can then have a script on the enemy that only the server runs that moves the enemy around, and just syncs the results to the clients by observing NetworkRigidbody (on the clients).

My question is, what if I want to have a bunch of objects in the scene that don’t get Network.Instantiated, but are just in the scene by default (like scenery, barrels, crates, etc)., that I want to move authoritatively? How would I make the server the owner of those objects?

Hi JRavey,

thank you so much for your help, now all the objects are ok, and I let the server calling the Network.Instantiate for each prefab. What I don’t understand is the newtowork ID thing. (sorry it’s just that I’m new to all the unity package). The problem I have now, if a client manipulate an object, if it is moved for example, it affects only the client’s view and not the other views. So… what the OnSerialNetworkView() is for? and do you have any suggestion on how to keep each view up-to-date? :slight_smile:

many thanks,
GC.

Make sure each network view has a valid observed component.

Sorry but I keep not understanding… :frowning: I’m very slow I apologies.
This is my situation: 1 server, N clients. When a client wants a prefab, an RPC is called to the server. The server calls the Network.Instantiate for the prefab asked by the client. Each prefab has a NetworkView component. As the prefab is allocated by the server, the server is the owner. Right?. Ok.
Each prefab has a NetworkView observing … its own Transform (is that what you mean “Valid observed component” ?). So, now each client’s camera has a DragRigidbody.js script which allows picking the objects in the scene and move them. So, the client picks the objects and moves it. No view is updated. In the server view: it picks an object and moves it, all the views are updated. So, where the OnSerializedNetworkView() has to go? which script? in a script attached to each object?

Again I apologies for my slow comprehension :frowning:
Many thanks for the help.

I will explain more in a bit, I am about to go out. In this case, because each object is owned by the server, the server would be expected to update the clients. How would it know that one client wishes to move an object?

I really don’t get this NetworkView… as the documentation is quite poor. The server, owns all the objects and I though that as each object as a networkview observing their Transform component, the fact that a client is moving it, it is broadcasted in the network and kept all the objects up to date. Now, how would the server know if a client is moving or not an object, I don’t know. I always thought that the NetworkView ID was a kind of communication channel dedicated to keep up-to-date the Observed component. I don’t get then, how it is possible that if the server moves the objects then all the clients’ views are updated but not on the other way round… so it’s a one-way communication channel, isn’t it?
I don’t understand why if it works in one direction, it doesn’t in the other way round?

GC.

If the server owns it, it writes to the network view.

It is automatically determined if the variables being serialized should be sent or received, see example below for a better description. This depends on who owns the object, i.e. the owner sends and all others receive.

It took a little bit of testing and such for me to get this. In one current project, all input is sent to the server who updates everybody. RPCs are used to instantiate objects (not Network.Instantiate), then input is sent from clients to that server who processes the information, updates object data and then that is updated through network views.

In your case, if the server owns everything, then you need to get input from each Network.Player and then apply that to the appropriate objects using server-side code. When the server updates the objects, the NetworkViews will then update each object appropriately.

But JRavey, if I have a bunch of objects already in the scene that don’t require instantiation, like scenery stuff (barrels, boxes and whatnot), and I want them all to be owned by the server so I can have the clients push them around authoritatively, how would I set the owner of them?

If they are part of the scene, the server should own them. When the clients move on the server from client input, they will update the clients with the networkview of each object which has moved.

Ohh thank goodness, that makes my life easy. So all objects in the scene are by default, owned by the server, unless otherwise specified manually through code, or Network.Instantiated?

And am I correct in assuming that if something is Network.Instantiated, that object is owned by the person who called Network.Instantiate?

http://unity3d.com/support/documentation/Components/net-NetworkInstantiate.html
Network Instantiate lets you Instantiate a prefab on all clients in a very easy to use way. When a player calls Network.Instantiate(), they control any Input commands on that GameObject. All the setup and handling is performed under the hood, so all you need to do to assign control is make each player call Network.Instantiate() on the GameObject they should control.

That is a roundabout way of saying they own it.

Awesome, thanks a bunch for the clarification, man.

So would you consider my way of using Network.IsServer to destroy or disable any script that Network.Instantiates objects that i want to control authoritatively (like enemy spawn points) a cheesy way of doing it? :slight_smile:

A spawn point doesn’t really need a network view if the enemies spawning from it already have them. You could put a network view on there if you wanted, particularly if it should be animated or something. You could make the spawn points, then have them automatically spawn by using an RPC which tells them to spawn something or just have them use an Network.Instantiate.

But if I didn’t have a network view, I can’t use any of the network conditionals like Network.IsServer, or use Network.Instantiate, right?

The only reason I have a networkview on it is so in Awake() I can check if the current player is the server, and if not, destroy it… that way the server is the only person running the code on it, and thus the only person Network.Instantiating the enemies when a player gets near the spawn. I need him to be owner of the enemy that spawns, so he can run the AI movement logic (again, just using Network.IsServer to disable the AI logic script), and just sync the movement results to the other players by having a networkview observing NetworkRigidbody.cs.

I guess I could get away with not destroying the spawn objects, and just have the players that get within spawn distance of the object send an RPC to the server, and then that RPC would call network.instantiate, and the effect would be the same, no? I just figured this way, there is a little bit less code running on the clients, so it would be a little more optimized for them (although I suppose that would also mean its a little more cpu-intensive to be a host).

If the players are within the appropriate distance, the player’s client should not send an RPC as the server already knows they are there. The server would have enough information to instantiate something.

Remember, in an authoritative model, the clients are basically getting input and displaying output. If the player enters a trigger on the client, then they must have entered it on the server.