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

2

11

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!

Greenness answered 23/2, 2018 at 14:35 Comment(0)
G
1

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.

Greenness answered 26/2, 2018 at 10:47 Comment(0)
E
4

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.

Etamine answered 10/8, 2018 at 13:22 Comment(0)
G
1

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.

Greenness answered 26/2, 2018 at 10:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.