Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity [UNET] Sync non-player object transform not working

I am trying to sync the transform of one non-player gameobject in Unity by using UNET. Basically I have a player that can go against that object and move it, and I want the transform of that object to change in the same way in both the server and client.

I followed the tutorial https://unity3d.com/learn/tutorials/topics/multiplayer-networking/handling-non-player-objects?playlist=29690 and can get the player + bullet example to work well. I then created a new object, added the Network Identity with local player authority and Network Transform (update 1 sec) to it, created a prefab and added it to the Network Manager as a "Registered Spawnable Prefab".

Thought that this would be enough, but it doesn't work as the object transform is not updated in the same way in both the server and client. In the server, the collision is very strange (e.g. a straight movement against the object makes it jump back sometimes) but the object can be moved to a certain location and stay there. In the client side, when the player touches the object the collision is very smooth and then the object has some sort of magnetic effect that always brings it back to the transform of the object that is on the server side.

I checked these other questions: 1) Unity [UNET] Sync non-player object transform 2) How do I sync non-player GameObject properties in UNet/Unity5? and 3) UNET - Sync. script for color on non-player object, but I cannot make sense of the solution in 1) and how to use the SyncVar for syncing transforms (and if that is actually the best solution)

I also tried the Unity tutorial above on setting up my object exactly like the enemy case, but it also does not work to keep the transforms synced in both the client and server.

I am sure I am doing something very stupid, so any tip is greatly welcome!

like image 238
jaraujo Avatar asked Feb 23 '18 14:02

jaraujo


2 Answers

Important .. for 2018 ..

we determined

There is some flakiness with NetworkTransform if you are using localhost during development, perhaps particularly on Mac.

it's a real PITA. Be sure to test on normal LAN with a few machines.

like image 191
Fattie Avatar answered Nov 09 '22 05:11

Fattie


Found the solution. Somehow the Network Transform component in the object was set for "Sync 3D Rigid Body" instead of "Sync Transform" in the parameter "Transform Sync Mode". Changing to Sync Transform instead solved the problem and the "magnetic" or "elastic" effect does not occur anymore.

like image 1
jaraujo Avatar answered Nov 09 '22 05:11

jaraujo