NetworkTransform doesn't sync data with new connected client.
See original GitHub issueDescribe the bug I synced the transform position of my doors. It’s well synced when the host or the client trigger the button to open the door or close the door. But if my host open the door when my client is not connected, when the client connect to the host, the door which is open on the host, is closed on my client.
To Reproduce
- Create a gameobject with a NetworkObject and a NetworkTransform component.
- Start Host
- Move the object on the host side
- Connect a client to the host => The object is still at the original position on the client side, which is not the host side object position.
Expected behavior When the client connect, the server should send all actual position of NetworkTransform objects to the new connected client. The client should apply all the positions of these objects before allowing the user to play.
Screenshots
Environment (please complete the following information):
- OS: Windows 10
- Unity Version: 2020.3.0f1
- MLAPI Version: 12.1.7
- MLAPI Commit (not sure it’s the good one tho)
Additional context Luke helped me to find a workaround and use this part of the code :
if (!IsOwner)
{
if(!isDoorOpened.Value){
GetComponent<NetworkedTransform>().Teleport(originDoorPosition, Quaternion.identity);
}else
{
GetComponent<NetworkedTransform>().Teleport(new Vector3(originDoorPosition.x, 3, originDoorPosition.z), Quaternion.identity);
}
}
It works well. He told me that’s because the server doesn’t send the actual position and when I try to move any NetworkTransform object by updating it’s position or translate it directly on the client, that doesn’t work because the NetworkTransform will automaticaly remove the object to the last known position. By using the Teleport method on the NetworkTransform component, it update the known position of the component which will be the same as the server, so it’s fine.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
We are aware of this and a future MLAPI version will address it
Hi, @ashwinimurt . In release 1.0.2 version this issue still exists. Found a workaround to set position threshold to 0.
Pros: really fast solution Cons: send package each tick, still need one tick when connects to sync.
With tick rate set by default (30) sending 3 floats during 1 minute takes: 3 * 4 * 30 * 60 = 21600 bytes ~ 21 kilobytes. I think is not so bad.
Please correct me if I am wrong.