Help with using OnSerializeNetworkView() in network multiplayer game

Hello

I am a newbie in doing network programming.

I am trying to make a multiplayer game for network, and want to synchronize the game characters between the different maschines.
I’ve tried to search on the Unity documentations and found a guide that told me to use the function OnSerializeNetworkView() and followed the steps in the article but i does not work. The function is never called. (I’ve tried to insert a debug msg in the function and it is never called).

Does anybody have some good surgestions to what might be wrong?
The project is attached to this post.

834629–31127–$Arena.zip (59.7 MB)

Did you set the observed property of the networkview to the script ?

no, I don’t think so.
How do I do that?

You drag the script that contains the OnSerializeNetworkView function onto the observed property of the networkview.

Now it ALMOST works… my problem is that when I edit the values (in Unity) it is only the opponent characters which is being updated.

I don’t understand what you mean by that, can you clarify ?

What I do is, that I am starting a server directly from inside the unity editor, and connecting to it from a built version of my game.
When you join the server you instantiate a character, the same counts when you are starting the server.
The character has a script attached to it with a lot of different properties, such as health, power and armor.
But when I am editing these properties in unity, the client does not update the character which it has instantiated itself.

If I still am not explaining it well enough, maybe you could download the product and see what I mean?

Thank you for your quick responses

Syncing properties does not happen out of the box, you need to write code for it.
So either you didn’t do that yet or there is a problem with the code.
So please post your code and explain what you are trying to do with it so we can help.

void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info)
	{
        if (stream.isWriting)
		{
			Vector3 posS = transform.position;
			int powerS = power;
			int armorS = armor;
			int healthS = health;
			
			stream.Serialize(ref posS);
			stream.Serialize(ref powerS);
			stream.Serialize(ref armorS);
			stream.Serialize(ref healthS);
        }
		if (stream.isReading)
		{
			Vector3 posR = Vector3.zero;
			int powerR = 0;
			int armorR = 0;
			int healthR = 0;
			
			stream.Serialize(ref posR);
			stream.Serialize(ref powerR);
			stream.Serialize(ref armorR);
			stream.Serialize(ref healthR);
			
			transform.position = posR;
			power = powerR;
			armor = armorR;
			health = healthR;
        }
    }

Why don’t you use Photon Networking or a similar system? I haven’t tried it, as my current project has no networking function, but I hear it’s pretty good and superior to Unity’s built in networking.

As for your code, I don’t quite think you’re doing it right…

Tobias just did a nice simple Tutorial:

give it a try, Chris

One of the links on that Web page needs to be changed. The “Photon Viking Demo” link goes to the “Photon Unity Networking” package and not to the “Photon Viking Demo” package.

“Everything needed, is in the package, so we create a new, empty project in Unity. In the Asset Store, search for “Photon Viking Demo” (or click the link). Download and import the package.”

lockbox: Thanks for the hint! Going to change it.