I’m trying to implement object grasping using the XR Interaction Toolkit.
However, I’m also using NetCode for GameObjects.
In this setup, the VR player is the client, and I want to ask the host whether the object can be grasped.
If it can, the grasp should proceed; if not, the grasp should fail.
To achieve this, I need to pause the grasp process and wait for the host’s response before continuing.
Could anyone advise on how to implement this?
Currently, I’ve created a custom class that inherits from XRGrabInteractable and overridden the OnSelectEntering(SelectEnterEventArgs args) method.
In this method, I attempt to call base.OnSelectEntering(args) after receiving a response from the host.
However, I get the following error while waiting for the host’s response:
An Interactor received a Select Enter event for an Interactable that it was already selecting.
UnityEngine.XR.Interaction.Toolkit.XRInteractionManager:Update () (at ./Library/PackageCache/com.unity.xr.interaction.toolkit@2.5.2/Runtime/Interaction/XRInteractionManager.cs:401)
It seems that a check is being done in the XRInteractionManager’s Update() method.
The process works as expected, but the error is concerning.
Could someone advise on the correct way to implement this?
Version Info:
Unity 2022.3.10
XR Interaction Toolkit: 2.5.2
Netcode for GameObjects: 1.9.1
Hi,
I believe what you want to do is to check whether you CanSelect an object, rather than canceling the grasp process when select has already been going on the client. You can override the method CanSelect on your Interactor object to allow it only when the host says so.
Another solution that would work without communication on whether the client can grab the object or not but might be more prone to lag is to only add the XR Interaction Toolkit on the server. This way, your local client will only have basics XR components to navigate, and when an input is triggered, the server-side of your client will be grabbing the object if grab is allowed. Only the position of the object will be synchronized when grabbed, not the state of the object
Last advice : you should check the XR Interaction Toolkit template with Netcode for Gameobjects made by the Unity team, called “VR Multiplayer Template” (on version 2.0 : VR Multiplayer Template Quick Start Guide | VR Multiplayer | 2.0.4) - you could find a better implementation of XR networking interactions that we’ve just discussed
Thank you very much!
I will check CanSelect first and comment again.
Thanks also for the information on VR Multiplayer Template. I will check this one after that as well.
1 Like
I was able to implement it by modifying the CanSelect of the Interactor.
Thank you very much.
(Technically, I also modified CanHover.)
1 Like