- Home /
Cant get Attach Transform of interactorObject.
I was following this tutorial: https://www.youtube.com/watch?v=XRaNYOXU0hw Code:
using UnityEngine; using UnityEngine.XR.Interaction.Toolkit; public class OffsetInteractable : XRGrabInteractable { protected override void OnSelectEntering(SelectEnterEventArgs args) { base.OnSelectEntering(args); MatchAttachPoint(args.interactor); } private void MatchAttachPoint(XRBaseInteractor interactor) { bool isDirect = interactor is XRDirectInteractor; attachTransform.position = isDirect ? interactor.attachTransform.position : transform.position; attachTransform.rotation = isDirect ? interactor.attachTransform.rotation : transform.rotation; } }
And everything works just fine but it says that args.interactor is Obsolete and instead interactorObject should be used. Even though it works fine like this, I didn't want to have an Obsolete method.
I tried using private void MatchAttachPoint(IXRInteractor interactor) { bool isDirect = interactor is XRDirectInteractor; attachTransform.position = isDirect ? GetAttachTransform(interactor).position : transform.position; attachTransform.rotation = isDirect ? GetAttachTransform(interactor).rotation : transform.rotation; }
and private void MatchAttachPoint(IXRInteractor interactor) { bool isDirect = interactor is XRDirectInteractor; Transform GrabTransform = GetAttachTransform(interactor); attachTransform = isDirect ? GrabTransform : transform; }
but couldn't achieve the desired effect as shown in the video.
It's also said in Unity docs that IXRInteractor interactorObject should be used instead of XRBaseInteractor interactor. https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@2.0/api/UnityEngine.XR.Interaction.Toolkit.BaseInteractionEventArgs.html https://docs.unity3d.com/Packages/com.unity.xr.interaction.toolkit@2.0/api/UnityEngine.XR.Interaction.Toolkit.XRBaseInteractable.html
Any help appreciated
Answer by Avinoamaj · Apr 28 at 09:32 AM
Hey, I just figured it out: first, you're gonna have to use "SelectEnterEventArgs args" and "SelectExitEventArgs args" respectively in all of the functions. In the 2.0.0+ versions of the XR toolkit, they refer to the selection of an object as an "event object" which means the "args" will contain both your interactor and your interactable (the "hand" and the selected element).
now, every time you need to refer to the Attach Point between the interactor and the interactable you can use this: args.interactorObject.GetAttachTransform(args.interactableObject)
(continuing with either .position / .localposition or .rotation / .localrotation)
the rest of the script remains pretty much the same.
I'll attach my complete updated script as a TXT file here.
,Hey, I just figured it out: first, you're gonna have to use "SelectEnterEventArgs args" and "SelectExitEventArgs args" respectively in all of the functions. In the 2.0.0+ versions of the XR toolkit, they refer to the selection of an object as an "event object" which means the "args" will contain both your interactor and your interactable (the "hand" and the selected element).
now, every time you need to refer to the Attach Point between the interactor and the interactable you can use this: args.interactorObject.GetAttachTransform(args.interactableObject)
(continuing with either .position / .localposition or .rotation / .localrotation)
the rest of the script remains pretty much the same. I'll attach my complete updated script as a TXT file here.
Your answer
Follow this Question
Related Questions
XRGrabInteractable track velocity, not position 0 Answers
XR Interaction Toolkit - Grab Object Persistent 0 Answers
How to make audio interact with visual in VR? VRTK 0 Answers
[Unity VR] Interactive moving box with functional lid? 0 Answers
Unable to add interactions to oculus handtracking in Unity 0 Answers