Player child gameobject with NetworkTransform

My player prefab has a network transform on it’s self and a child game object “head” with the camera.

When it is spawned in the game, the other clients aren’t moving the head move. The network identity shows:

Network ID: 0
Player Controller ID: -1

The top level NetworkTransform updates fine.

What am I missing?

I have this same issue. Except instead of heads its weapons not aiming.

I got the weapon to rotate, though its not great. What I did was remove the networktransform and network identity from the weapon object. Then added a [SyncVar] tag to a rotation variable. Here’s what I did. It might not be the best, but the movement shows up on the other clients.

Edited for readability

[SyncVar]
public float rotation;

void Update () {
if (isLocalPlayer)
{
rotation = Input.GetAxis (rotationAxis) * maxAngle;
}

weaponsArm.transform.localRotation = Quaternion.Euler (new Vector3 (0, 0, rotation));
}

Thanks. I was about to do that too.

It’s just we loose all the smoothing and network optimization and other benefits of the NetworkTransform. frustrating

I’m hoping someone more familiar with the tools will help us out in the morning.

According to the 5.2b1 release notes:

“Previously only player objects could have local authority, which meant that the NetworkTransform (and other components) could only be used for controlling the single player object for a connection on a client. With these changes it is possible to have multiple objects on a client that are locally controlled.”

And then it goes on to suggest you can now do it via using NetworkServer.SpawnWithClientAuthority() or NetworkIdentity.AssignClientAuthority().

However, so far, these calls can only be made on a server, and AssignClientAuthority() only works if the server spawned the object, and in a test I just ran, it doesn’t count spawning the player and the network identity being a child. It seemingly must be spawned as a separate object with SpawnWithClientAuthority(). So much for using prefabs with multiple network components. :frowning:

I expect SpawnWithClientAuthority() might work for you well though. You need to register your weapons as prefabs with the server.

So I’ve done it your way and it’s working

However it of course needed a [Command] to send the rotation to the server where it could change the syncvar to propogate to all clients ( as SyncVars are server to client only) which means all that extra traffic going through the server. (I was thinking the network transform was a bit smarter and able to send peer to peer - but I guess that’s wrong?).

I’ll dig around now to understand how to only keep the latest command, because in a congested network I don’t want a bunch of redundant data being sent.

The HLAPI isn’t all that great after all.

Pretty awesome! I was just reading about Command. Thanks for the help.