Search code examples
mrtk

How do I modify the GrabPointer prefab to allow for more than the default 64 colliders in a scene?


I have a similar question to this, however for SpherePointer.

Using MRTK 2.2 as acquired by NuGet for Unity, I'm getting this warning pretty much every frame:

Maximum number of 64 colliders found in SpherePointer overlap query. Consider increasing the query buffer size in the pointer profile.
UnityEngine.Debug:LogWarning(Object)
Microsoft.MixedReality.Toolkit.Input.SpherePointerQueryInfo:TryUpdateQueryBufferForLayerMask(LayerMask, Vector3, QueryTriggerInteraction)
Microsoft.MixedReality.Toolkit.Input.SpherePointer:OnPreSceneQuery()
Microsoft.MixedReality.Toolkit.Input.FocusProvider:UpdatePointer(PointerData)
Microsoft.MixedReality.Toolkit.Input.FocusProvider:UpdatePointers()
Microsoft.MixedReality.Toolkit.Input.FocusProvider:Update()
Microsoft.MixedReality.Toolkit.<>c:<UpdateAllServices>b__63_0(IMixedRealityService)
Microsoft.MixedReality.Toolkit.MixedRealityToolkit:ExecuteOnAllServices(IEnumerable`1, Action`1)
Microsoft.MixedReality.Toolkit.MixedRealityToolkit:ExecuteOnAllServicesInOrder(Action`1)
Microsoft.MixedReality.Toolkit.MixedRealityToolkit:UpdateAllServices()
Microsoft.MixedReality.Toolkit.MixedRealityToolkit:Update()

I was able to successfully remove the similar warning for PokePointer using @Julia's response but I'm stumped as to how to do it for the GrabPointer prefab.

This prefab has a SpherePointer script attached but the SceneQueryBufferSize property isn't exposed in the inspector because SpherePointer's custom inspector (ShperePointerInspector.cs) doesn't expose it.


Solution

  • Great question! It looks like you've actually found a bug. Please use the following code to work around this for now, we will post a fix shortly. The issue to track this is here: issue 6878

    // Copyright (c) Microsoft Corporation. All rights reserved.
    // Licensed under the MIT License. See LICENSE in the project root for license information.
    
    using Microsoft.MixedReality.Toolkit.Input.Editor;
    using Microsoft.MixedReality.Toolkit.Input;
    using UnityEditor;
    
    namespace Microsoft.MixedReality.Toolkit.Input
    {
        [CustomEditor(typeof(SpherePointer))]
        public class SpherePointerInspector : BaseControllerPointerInspector
        {
            private SerializedProperty sphereCastRadius;
            private SerializedProperty nearObjectMargin;
            private SerializedProperty grabLayerMasks;
            private SerializedProperty triggerInteraction;
            private SerializedProperty sceneQueryBufferSize;
    
            private bool spherePointerFoldout = true;
    
            protected override void OnEnable()
            {
                base.OnEnable();
    
                sphereCastRadius = serializedObject.FindProperty("sphereCastRadius");
                sceneQueryBufferSize = serializedObject.FindProperty("sceneQueryBufferSize");
                nearObjectMargin = serializedObject.FindProperty("nearObjectMargin");
                grabLayerMasks = serializedObject.FindProperty("grabLayerMasks");
                triggerInteraction = serializedObject.FindProperty("triggerInteraction");
            }
    
            public override void OnInspectorGUI()
            {
                base.OnInspectorGUI();
    
                serializedObject.Update();
    
                spherePointerFoldout = EditorGUILayout.Foldout(spherePointerFoldout, "Sphere Pointer Settings", true);
    
                if (spherePointerFoldout)
                {
                    using (new EditorGUI.IndentLevelScope())
                    {
                        EditorGUILayout.PropertyField(sphereCastRadius);
                        EditorGUILayout.PropertyField(sceneQueryBufferSize);
                        EditorGUILayout.PropertyField(nearObjectMargin);
                        EditorGUILayout.PropertyField(triggerInteraction);
                        EditorGUILayout.PropertyField(grabLayerMasks, true);
                    }
                }
    
                serializedObject.ApplyModifiedProperties();
            }
        }
    }