Unity [UNET] Sync non-player object transform
Asked Answered
H

1

1

I have a question regarding the UNET system.

There are some objects in the scene that can be picked. I want to synchronize transform that object when a player picks it up.

The object has a NetworkIdentity component with LocalPlayerAuthority checked. It also has a NetworkTransform script, but the transform synchronizes only from host to clients, not the other way around. So if I move the object on the host side all clients see the change, but if the client moves it only that particular client sees the change. What do I need to do in order to make it synchronized on both sides?

Hartzell answered 15/8, 2016 at 17:52 Comment(0)
H
0

Never mind, I already solved this problem.

What I had to do is to AssignLocalAuthority of the non-player object by using player object.

Hartzell answered 17/8, 2016 at 6:5 Comment(4)
will you like to share the code snippet in the answer too? i am encouting the same problem but don't how to set it.ThanksMichaelamichaele
On the player object, call AssignLocalAuthority in a command function (to invoke it on the host side) with the parameter of the netId of the non-player object. You can get netId from the NetworkIdentity component. I assign authority on a non-player object like this. Hope it helps: NetworkManagerVR.Instance.localNetworkPlayer.CmdAssignObjectAuthority(GetComponent<NetworkIdentity>().netId);Filigreed
Thanks, but you should add it in the answer, for future user also.Michaelamichaele
I check that non-player object authority automatically assign to host. Is this correct? because if i made host then i can interact with non-player object directly and their position/rot sync across network smoothly. while same is not true for the clientMichaelamichaele

© 2022 - 2024 — McMap. All rights reserved.