Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetObject/GetController variables/functions #89

Open
Slithersy opened this issue Mar 31, 2022 · 1 comment
Open

GetObject/GetController variables/functions #89

Slithersy opened this issue Mar 31, 2022 · 1 comment

Comments

@Slithersy
Copy link

Hello! I have noticed the XR Interaction Toolkit does not offer the most basic form of customization, actually being to adjust/know which object you are grabbing. This poses a massive issue where I MUST use a more expensive method such as raycast on update even though XR Interaction Toolkit is already raycasting to make it work properly, and even then it will not be fully reliable for certain actions.

I need to differentiate between a button and an interactable. To save on performance, I have decided to use the already built-in raycasting system that provides grabbing. Small issue, we have no access to this system.
So what? Are we just gonna have to code either our own grabbing system from scratch or use unreliable methods? This defeats the whole purpose. Please do something about this.

@langokalla
Copy link

Have you even read the documentation or tried the examples?

You can easily get both the "interactor" and "interactable" through every event fired by the interactors and interactables.

Take a look at the most basic of event arguments, the SelectEnterEventArgs.
Here you can access both the interactableObject and interactorObject. This applies for all other events also (hover, select, activate, deactivate).

To write it out in the simplest sample for you:

using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;

[RequireComponent(typeof(XRGrabInteractable))]
public class InteractorInteractableFinder : MonoBehaviour
{
   XRBaseInteractable m_Interactable;

   void OnEnable()
   {
      m_Interactable = GetComponent<XRBaseInteractable>();
      m_Interactable.firstSelectEntered.AddListener(OnFirstSelectEntered);
   }

   void OnDisable()
   {
      m_Interactable.firstSelectEntered.RemoveListener(OnFirstSelectEntered);
   }

   protected virtual void OnFirstSelectEntered(SelectEnterEventArgs args)
   {
      var interactor = args.interactorObject;
      var interactable = args.interactableObject;
      Debug.Log($"{interactor} selected/grabbed {interactable}.")
   }
}

Properly using the Interaction Toolkit does not require any extra raycast implementations at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants