Note that if you try to change the position of the GameObject inside this method, it will not work if you are using SetParent with keepWorldPosition: true (the default).
https://github.com/Facepunch/sbox-issues/issues/8724
There is a workaround:
https://github.com/Facepunch/sbox-issues/issues/8724
There is a workaround:
protected override void OnParentChanged( GameObject oldParent, GameObject newParent ) { _ = MoveAfterwards(); } // we need to wait so we're outside of OnParentChanged async Task MoveAfterwards() { await Task.Yield(); // it's possible the owner changed during that time, so tell the current owner of the object to move it. MoveIntoPosition(); } [Rpc.Owner] public void MoveIntoPosition() { WorldTransform = GameObject.Parent.WorldTransform; }
You may not need the third level of indirection if you're not changing owner at the same time, so you can just put the movement directly after Task.Yield().