0
\$\begingroup\$

I am new to both XR toolkit and Mirror and I have this problem that when I try to grab a box in online scene. It didn't work even thought it worked on the offline scene when I test it. anyone got any clue about this? or an example that I can use as a reference.

In my project I set the grabbable object to have a Network Identity , Network Transform and the xr grab interactable component, Then I set my player model(XR rig) to call server to assign authority when their hands touch the object. but for some reason there is no error or warning but I still can't grab/pick up the object

here's the code for authority assigning on the player hands:

   public class CubeAuth : NetworkBehaviour
{
    [SerializeField] NetworkIdentity me;
    private void OnTriggerEnter(Collider other)
    { 
        if (other.tag == "PickUp")
        {
            Debug.Log(other.gameObject.GetComponent<NetworkIdentity>().hasAuthority);
            CmdAssignNetworkAuthority(other.gameObject);
            Debug.Log("hit");
        }
    }
    [Server]
    //[Command(requiresAuthority = false)]
    public void CmdAssignNetworkAuthority(GameObject cube)
    {
        Debug.Log(cube.GetComponent<NetworkIdentity>().connectionToClient);
           /*if (cube.GetComponent<NetworkIdentity>().hasAuthority)
        {
            //Debug.Log("inside");
            // Remove authority
            cube.GetComponent<NetworkIdentity>().RemoveClientAuthority();
        }*/
        cube.GetComponent<NetworkIdentity>().AssignClientAuthority(me.connectionToClient);
        //cube.GetComponent<NetworkIdentity>().AssignClientAuthority(connectionToClient);

    }

p.s. it not an authority problem I tried.

\$\endgroup\$
6
  • \$\begingroup\$ You should post at least how you set up your object to work with mirror and what did not work in your online scene \$\endgroup\$ Commented Jan 31, 2022 at 11:13
  • \$\begingroup\$ alright I added more detail now. Thank for telling me, it my first time doing this. \$\endgroup\$ Commented Jan 31, 2022 at 12:22
  • \$\begingroup\$ Your code looks like you are assigning the authority to the PickUp object, not the cube (and you should have authority of that one already if it is the player object - usually spawned by the network manager). \$\endgroup\$ Commented Jan 31, 2022 at 12:24
  • \$\begingroup\$ but isn't "cube.GetComponent<NetworkIdentity>().AssignClientAuthority(me.connectionToClient);" mean that the server assign authority of cube(which is an object with a "PickUp" tag) to the client (me.connectionToClient)? \$\endgroup\$ Commented Jan 31, 2022 at 12:33
  • \$\begingroup\$ But where is the CubeAuth script located? On the cube you want to pick up or on the players hand? Does your xr grab interactable component has the network identity component assigned as well? \$\endgroup\$ Commented Jan 31, 2022 at 12:41

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.