VRTK icon indicating copy to clipboard operation
VRTK copied to clipboard

VRTK_UIPointer.GetPointerOriginTransform() breaks if SDK_BaseController.ControllerElements.AttachPoint returns null

Open beccannlittle opened this issue 8 years ago • 3 comments

Environment

  • Source of VRTK: Github
  • Version of VRTK: 3.3.0 (d88c9ea)
  • Version of Unity3D: 2018.2.6f1
  • Hardware used: Samsung Odyssey
  • SDK used: WindowsMR

Steps to reproduce

Set up a project for native WMR (NOT SteamVR). On your script alias(es), ensure you have VRTK_ControllerEvents and VRTK_UIPointer components. Also make sure you have an EventSystem component in the scene.

Enter Play mode and use the Activation Button for the UIPointer.

Expected behavior

No errors should occur.

Current behavior

Endless errors in the console:

ArgumentNullException: Argument cannot be null.
Parameter name: Name cannot be null
UnityEngine.Transform.Find (System.String n) (at C:/buildslave/unity/build/Runtime/Transform/ScriptBindings/Transform.bindings.cs:291)
VRTK.VRTK_UIPointer.GetPointerOriginTransform () (at Assets/External/VRTK/Source/Scripts/UI/VRTK_UIPointer.cs:528)
VRTK.VRTK_UIPointer.GetOriginPosition () (at Assets/External/VRTK/Source/Scripts/UI/VRTK_UIPointer.cs:423)
VRTK.VRTK_VRInputModule.CheckRaycasts (VRTK.VRTK_UIPointer pointer) (at Assets/External/VRTK/Source/Scripts/Internal/VRTK_VRInputModule.cs:48)
VRTK.VRTK_VRInputModule.Process () (at Assets/External/VRTK/Source/Scripts/Internal/VRTK_VRInputModule.cs:33)
VRTK.VRTK_EventSystem.Update () (at Assets/External/VRTK/Source/Scripts/Internal/VRTK_EventSystem.cs:50)

Taking a look at VRTK_UIPointer line 528, the script is executing VRTK_SDK_Bridge.GetControllerElementPath() for the AttachPoint Controller Element. SDK_WindowsMRController.GetControllerElementPath() essentially hands this job off to the MotionControllerVisualizer (not part of VRTK). This script does GetPathToButton > GetPathToVisualizedButton, which does not account for the AttachPoint Controller Element and returns null by default. Finally, Transform.Find() cannot accept null arguments - hence the errors.

Workaround

You might argue that the VRTK-Windows-MR-Extension project should just implement the AttachPoint Controller Element (and you'd be right!), but if you want to ensure that any other SDKs cannot also break VRTK_UIPointer then maybe we should ensure that we never pass a null value to Transform.Find(). Here's my workaround:

string path = VRTK_SDK_Bridge.GetControllerElementPath(SDK_BaseController.ControllerElements.AttachPoint, controllerReference.hand);
cachedPointerAttachPoint = path == null ? null : controllerReference.model.transform.Find(path);

beccannlittle avatar Sep 14 '18 17:09 beccannlittle

Good old Unity changing behavior to the worse :)

Please the (merged but not used by you according to your referenced commit) PR https://github.com/thestonefox/VRTK/pull/1873.

I'd vote against updating all usages of the method and instead making sure all SDKs properly return an empty string instead of null. I.e. hoping https://github.com/Innoactive/VRTK-Windows-MR-Extension/issues/10 gets fixed instead.

bddckr avatar Sep 15 '18 08:09 bddckr

Wait I may have spoken too soon. I believe the linked PR should actually fix this. Please test again on the latest master branch!

bddckr avatar Sep 15 '18 08:09 bddckr

Closing this as it's related to an older version of VRTK (v3.3) the master branch is now on VRTK v4. Feel free to request to reopen if the issue is still present.

thestonefox avatar Mar 30 '19 11:03 thestonefox