Since this post, I have done a fair amount of work toward this problem. I can’t see any movement with Unity MLAPI to support this case. I’ve outlined the options in this video:
I have another solution using Netcode for Game Objects (Unity’s new multiplayer system), for whoever reads that in the future:
I have two players that are NetworkObjects, and a ball which is spawned by the server, which also is a NetworkObject, with a ClientNetworkTransform.
Also, the ball has a script where we have a Transform to the hand holding it (null if nobody holds it).
When one player takes the ball, I assign the Transform of its hand to the ball (either direct function or ServerRpc if client is taking it).
Then in the ball script’s Update function I simply set the position to the holdingHand position.
unity_KE7F8ZJogU7_Lw solution is exactly the same as I use in the video - you manually set the transform of the owned object.
NGO 1.0.0, sadly, doesn’t help.
I’ve spent 5 months moving from Mirror to NGO and, sadly, NGO falls just short of what’s needed for pick up and drop. The problem (as I’ve written elsewhere) is that you need the player’s hand game object to be a network object so that the thing you’re picking up can attach to it. BUT prefabs (which the player must be) cannot have nested game objects in them. So the hand can’t be a nested game object. I know that the Boss Room does it using a constraint but the problem here is that you can’t have Network Objects in hierarchies in prefabs.
I explain it in more detail in this video (timestamp 4:51):
Really looking forward to seeing a proper fix for this - or at least spreading this knowledge around the Unity support team so I don’t have to explain it to Unity again.
its halfy done, its still a bug when a player wants to parent a network object under one of his tranform children that cant have a network object as it should be on the root of transform
Do you mean something like a prefab hammer with its own network object cannot be made a child of the Pawn’s hand bone because the Pawn has its network object at its root transform?
The problem is still that you need the hand to have an Network Object so that it can be a parent and you need the Player prefab top level to have a Network Object. You cannot have more than one Network Object in a prefab.
A workaround is to spawn the hand onto the player after the player prefab has spawned. While that works, it makes a lot of the code complex and if the hand is a couple of objects down the hierarchy then each of the objects in the hierarchy need to be spawned in the same way because to be parented, you need to have a Network Object.
It’s got nothing to do with whether the hammer has a Network Object enabled or not.
Yep. I looked through the documentation provided above in this thread. It makes clear that what you described is not a bug, but how Unity intends for NGO to work with parenting scenarios. I apologize for not having looked sooner.
Just a heads up that I have been bashing my head against this problem and your threads on it came up, and I have a solution. The one from your video where you have a separate visual item for a held object and switch it on/off is appropriate for circumstances where you have generic items but I’m working on a game where you have to pick up and move objects that have ropes and physics objects attached, so it has to be the real actual in-world item that goes in the hand.
Picking up and dropping items is still handled by the server, and the item gets parented to the player’s root (because as you discovered, that’s really the only place it will actually let you put it).
The items that can be picked up have a regular non-network monobehavior script on them. That script detects when the item has been parented to a player type object. It searches the player for the Hand transform, and each frame it moves the item to match the hand transform’s position and rotation. We basically fake that it’s in the hand without having to parent it to the hand.
This is the important bit. In that same script on the item, we disable the item’s NetworkTransform when it’s picked up and re-enable it when the item is dropped. This stops the item from syncing while it’s being held, so every observer sees the item exactly wherever it sees the hand bone is.
Essentially, the visual placement of a held object can’t be reliant on any network code, you only use the network for items that haven’t been picked up and for the pick up and drop code. If you give anyone authority over the position the item is in, it’ll only look right on their machine and everyone else will see it wrong. So instead the server just parents/unparents the item to the player roots and then any item that’s being held autonomously “moves” itself to the correct place.