- Home /
Child transform of player object not syncing with server
I have a player object with the hierarchy shown here Player has the NetworkTransform and NetworkIdentity component attached, also with the Controller.cs script which has the function Looking () shown here
private void Looking (float h, float v) {
//Called every Update ()
transform.Rotate (0F, h * sensitivity, 0F);
Head.Rotate (v * sensitivity, 0F, 0F);
//Head is the transform for the game object, Head, in Player
if (Head.localRotation.eulerAngles.y != 0) {
if (Head.localRotation.eulerAngles.x > 270F)
Head.localRotation = Quaternion.Euler (-90F, Head.localRotation.y, Head.localRotation.z);
else
Head.localRotation = Quaternion.Euler (90F, Head.localRotation.y, Head.localRotation.z);
}//if
}//Function Looking
Which works wonderfully for the client. How ever trying to do anything with Head only results in changes on the client and not the server.
Picture to better describe the problem
Answer by AlienNova · Oct 24, 2017 at 12:43 AM
Okay, so I found the answer after some more intense reading of Unity's network manual. For anyone else that finds themselves here with the same problem: https://docs.unity3d.com/Manual/class-NetworkTransformChild.html
I have an FPS controller GameObject as the root with a camera as the child to it, probably similar to what you have in this example.
The parent has NetworkIdentity, NetworkTransform client authority = true, and NetworkTransfromChild client authority = true with the head gameobject dropped into the target variable.
$$anonymous$$y player body transform is updated, but the rotation of my player's head is not sent to the other player.
I appear to have the same exact issue has you, and cannot find the solution.
I was wondering the same thing, and I think AlienNova is referring to "Child transform to be synchronized. (Remember, this component goes on the parent, not the child - so you specify the child object using this field)." I was seeing the same issue, until I put the NetworkTransformChild component on the parent object, then set the target to the desired transform child.
Answer by kalibcrone · Dec 10, 2020 at 05:15 PM
I do not know if you are having the same issue as me, but when I had this issue, I was accidentally only grabbing the transform of my player's head model, but technically it was the head's parent gameobject that was moving the model, so both the gameobject with the mesh renderer for the 3d model as well as the parent gameobject which rotated the model, needed to be dragged into a NetworkTransformChild component on the root gameobject.