very simple multy-player

Hello Guys,

I want to create a very simple multyplayer environment where objects can be moved by any of the players connected. Whenever a player moves an object, the other players will see it. So, I am following this tutorial:

http://download.unity3d.com/support/resources/files/MultiplayerTutorial.pdf

my scene has 2 cubes and their settings look like in the picture. So I have NetworkRigidbody.cs (from the tutorial) and RigidAssign.js (from the tutorial too). The two cubes already are in the scene, so I start the server, and 2 clients. When the server moves the objects, clients will see it, BUT when one of the clients move the objects, nothing happens in the other client’s view and server’s view. Both the cubes as a networkview which observe networkRigidbody.cs so… I am getting stuck :frowning:

Any Help would make this rainy day in London (UK) much nicer :slight_smile:

Thanks!

Do you understand what networkviews and NetworkRigidbody.cs do ?

Well I tried. My understanding is that usually Networviews will send the Transform of the objects over the network, but in this case Networkviews observe the NetworkRigidbodies.cs… so this will enable the OnSerializeNetworkView to send/receive objects’ positions. That’s my understanding.
As the OnSerializeNetworkView is split in 2 parts, when it reads and when it writes, and as in the tutorial they said that the script it’s kinda standard one, I thought to use it.

ok, if you know that part then it should be easy to troubleshoot.
Basic test would be to have the editor and a client.
Move the object in the editor and see if the client sees it.
From the moment the networkview gets input from the script, it sends it over the network.
Debug in steps, first check if the networkview sends his input…
Is your setup authoritative ?

Well,

let’s say, that I just copied and pasted those script file in a much simpler project. So, I guess I’m building an authoritative one. So, in the editor I ran the server, then in another window I ran the client… uhm probably the editor should run the Client and the server would be a different window … but I have a question regarding the ownership of an object. As the two cubes are already in my scene, who’s the owner?

Guessing in network programming is a bad option.
The server would be the owner but i’m not sure.
In normal setups the instance that instantiates the object is the owner.
In authoritative configs the server is allways the owner but it can tell a client to have controll over an object.

Well, in a networked setting I made a prototype where the server calls the network.instantiate for the objects. So I know the server will be the owner. Now, each object has a Drag.js script which allows clicking on it and moving/dragging around. Clients will drag objects around but if they are not owner I think the OnSerializedNetworkView won’t send around the information, as I read: “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.”
But I wonder, if a client doesn’t own the object, what is happening with the OnSerializedNetworkdView?

i don’t understand your question, OnSerializeNetworkView is only resposible for sending and receiving data.
if your object is server owned, you will need to have the server tell the client that it can move the object.

Uhm, I thought that if the server owned object is moved by a client, the OnSerializedNetworkedView would receive the data automatically from whoever is sending :frowning:

a client can’t move an object that he doens’t own

What if I use an RPC call, everytime a cliends moves locally a copy of the object, it calls that RPC with Mode.Server so the server will move it accordingly and the rest of the client will see it, hopefully… those that would make sense? :slight_smile:

btw, I don’t understand then the OnSerializedNetworkedView then, I took the script component off and I got the same behaviour as before. I’m getting confused.

Acutally I just realized a very simple way by calling an RPC function … very nice and simple, yet not efficient considering the bandwidth may be but … it’s a starting point! :slight_smile: