Setting local position of a child on a network object - transform reports parent's world position

SImple Netcode set up (2.4.2) . Unity 6000.1. Default Networkmanager.
I have a scene object (NetworkObject) call it Object1. Object1 has world coordinates of (0, 1.18,-24).
I have a simple capsule representing the player’s body, call it Player. This is NetworkObject and NetworkTransform. In the NetworkTransform I have set “Switch transform space when parenting”.
I have a Rpc(SendTo.Server) that does:

Player.GetComponent<NetworkObject>().TrySetParent(Object1);
//Also tried the simpler: Player.transform.parent = Object1.transform;
Player.transform.transform.SetLocalPositionAndRotation(Vector3.zero, Quaternion.identity);

When I Debug.Log the Player.transform.LocalPosition after this, it reports (0,0,0), but when I select the Player object in the scene (spawned) which is nicely parented to Object1, I see (0,-0.17,24)!! The values in the Inspector should represent the Local Position and say (0,0,0).

Does anyone know why this is happening?

At what point “after this”? The change may not take effect immediately but only after a network tick. Do log that value in Update to see if it changes eventually.

The issue may also be caused by the parent object moving after the child object was added/moved.

Also, deduplicate the .. .transform.transform. ... A transform’s transform is the same transform’s transform. :wink:

And generally speaking: avoid parenting network objects as if it were the plague! It needlessly complicates everything. This Object1 could be your controller for all child object’s networking matters. If the player needs to call an RPC, it does so by routing through Object1. If Object1 receives an RPC, it invokes an event that the Player listens to. That way, player can be a non-NetworkObject object.

Right. Sorry about the double transform, typo :slight_smile:
So, I did away with the parenting.
I’ve still got a similar problem. I probably miss something in who (server or client) does what.
Okay. Player object (NetworkObject and NetworkTransform). The transform is set to Owner so the client can control its position (this is what I need). Otherwise the settings are all default.
Start the server. Start the client. Player is spawned as it should.
Then the client need to press an on-screen button (Start). The first action is to move the Player object to a new location in the scene. I do this only on the client (IsClient etc) as the client is the owner of the Player object.
I do a simple:

player.transform.position = Vector3(x,y,z);

When I do a Debug.Log of the player’s position is reports (x,y,z) as it should, however the player object in the scene has not moved.

I feel I’m missing something fundamental here :slight_smile:

Cheers!

It’s better to use IsOwner since the host is also a client. If the host also runs this code it might override/overrule the position change.

I’m not familiar with NGO 2.x but in 1.x you needed to use a ClientNetworkTransform subclass that overrides the IsAuthority property to return true so that clients can change the transform. This wasn’t allowed even for the owner without that flag.

Cheers!
I’m running a server so I could use either IsOWner or IsClient I think. But good point!

They’ve changed a lot in HGO 2+ from 1+ including the network transform etc. :slight_smile: