How to change ownership on interactables in netcode

Hi
I have a netcode project with an XROrigin and a NetworkPlayer prefab. One player starts the application and automatically opens the server as a host and the second one automatically joins after opening the application. Now I want just a ball that can be picked up and held by both, this ball should be synchronized. The ball gets spawned by pressing SPACE as the host. The host can also take the ball and the 2nd client sees this synchronized. But if the client wants to take the ball it is 1. not snyced with the host (he just doesnt see it) and 2. the ball gets teleported back to the original position after deselecting it. I tried to change the ownership. I copied a method from a tutorial and bound this method to the controllers of the XROrigin when Selected on a XR Direct Interactor. This method is within the NetworkPlayer Script that lies on the NetworkPlayer prefab:

public void OnSelectGrabbable(SelectEnterEventArgs eventArgs)
{
   Debug.Log("Trying to pick up for this OwnerClientId " + OwnerClientId);
   Debug.Log("NetworkId " + NetworkObjectId);
   Debug.Log("IsClient: " + IsClient + " IsOwner: " + IsOwner);

   if (IsClient && IsOwner)
   {
   NetworkObject networkObjectSelected = eventArgs.interactableObject.transform.GetComponent<NetworkObject>();
   Debug.Log("This is the selected object: " + networkObjectSelected);
   if (networkObjectSelected != null)
   {
       RequestGrabbableOwnerShipServerRpc(OwnerClientId, networkObjectSelected);
   }
   }
}

[ServerRpc]
public void RequestGrabbableOwnerShipServerRpc(ulong newOwnerClientId, NetworkObjectReference networkObjectReference)
{
   if (networkObjectReference.TryGet(out NetworkObject networkObject))
   {
       if (networkObject.OwnerClientId == newOwnerClientId)
       {
           return;
       }
       Debug.Log("This is the selected object: " + networkObject);
       Debug.Log("And this the client ID: " + newOwnerClientId);
       networkObject.ChangeOwnership(newOwnerClientId);
   }
   else
   {
       Debug.Log("Unable Changeownership for: " + newOwnerClientId);
   }
}

There are some weird behaviours now. A normal session on a client looks like this:
Host is hosting

  • Spawning this OwnerClientId 0
  • NetworkObjectId 1, IsClient: True, IsOwner: False

Client is joining:

  • Spawning this OwnerClientId 1
  • NetworkObjectId 3, IsClient: True, IsOwner: True

Then the ball is spawned with NetworkObjectId 4 and OwnerClientId 0 (spawned by host) If I now want to take the ball as a client it logs these values: OwnerClientId 0, NetworkObjectId 0 IsClient: False, IsOwner: False And I dont understand that, I didnt even found an object in the hierarchy with the NetworkObjectId 0.
I used a tutorial from valem to setup the project and unity relay. And the interactable code is from dilmer valecilos

Ping … any news on this?

Hi,
I really appreciate your fast support. In particular - since this is a widely discussed challange I am facing e.g.:

I am using:

  • 2022.3.16f1
  • Netcode for GameObjects 1.7.1
  • Relay 1.0.5
  • XR Interaction Toolkit 2.5.2
  • 2 Meta Quest 3

Following the SETUP mentioned here:

GOAL: Each player is able to spawn objects that can be grabbed (XR Grabble) and moved arround by both players.

PROBLEM: If client player grabs, moves or rotates the object, it snaps back to the old position after exiting select. I’m facing the problem even if i requestchange ownership via serverRPC. Reuqesting the ownership slightly changes the behavior - meaning that very small changes of rotations seam to be transmited to the sever somehow.

ASSUMPTION: The missmbehavior ist somehow related to the fact that the grabbed object is reparented for interaction - but I am not sure.

In the attachement you will find a screenshot of the object. In addition I attached the changeOwnership script.

Does it make sense?
Dd you need any additional information? .. upload screen recordings?
Is there any sample showing how to have a xr grabbable object being moved arround by two players with netcode for GameObjects and Relay? I means this seamas to me a very obvious XR use case.

Your help is very appreciated! Hope to hear from you soon!

BR,
Andreas

9608420–1362947–NetworkGrabbableObject.cs (1.69 KB)

I’m facing the same problem.

This is happening on client:

Is there someone who can help me with a simple example of how to do grabbing over netcode using xr grab interactable?

Hi guys, I’m facing the same problem, but I found some light that may help. I have not try it yet, so you may try and tell if it worked or not. Anyway, let’s go:
He’ll explain in the video, but basically what he did was that the server moves the cube to follow the client’s hand.