Search Unity

  1. Unity wants to learn about your experiences working on a Unity project today. We'd like to hear from you via this survey.
    Dismiss Notice
  2. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice
  3. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  4. Dismiss Notice

Resolved Can't figure out the cause of the input system error.

Discussion in 'EditorXR' started by Taiyo_no_gosaiji, Jan 12, 2021.

  1. Taiyo_no_gosaiji

    Taiyo_no_gosaiji

    Joined:
    Dec 10, 2020
    Posts:
    4
    I use machine translation, so please forgive me if my English may be unnatural. 
    I have written this code for a new object controller tool. It is a tool to test the input system.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEditor;
    4. using UnityEditor.Experimental.EditorVR;
    5. using UnityEngine;
    6. using UnityEngine.XR;
    7. using UnityEngine.InputNew;
    8.  
    9.  
    10. public class LaserbeamController : MonoBehaviour, ITool, IUsesRaycastResults, IUsesViewerScale, ICustomActionMap, IProcessInput,
    11.     IGetVRPlayerObjects, ISelectObject, IUsesRayOrigin
    12. {
    13.  
    14.     GameObject ManipuratorBase;
    15.  
    16.     bool ControlObject = false;
    17.    
    18.     LaserbeamAction laserConInput;
    19.  
    20.     Vector3 LaserOriginePosition;
    21.     private Vector3 offset = new Vector3(0.0f, -0.3f, 0.5f);
    22.  
    23.    
    24.    
    25.     GameObject player;
    26.  
    27. #pragma warning disable 649
    28.  
    29.     [SerializeField]
    30.     GameObject laserPrefab;
    31.  
    32.     [SerializeField]
    33.     GameObject depthController;
    34.  
    35.     [SerializeField]
    36.     ActionMap laserConAction;
    37.  
    38. #pragma warning restore 649
    39.  
    40.     public Transform rayOrigin { get; set; }
    41.     public ActionMap actionMap { get{ return laserConAction;} }
    42.     public bool ignoreActionMapInputLocking { get {return false;} }
    43.  
    44.  
    45.     public void ProcessInput(ActionMapInput input, ConsumeControlDelegate consumeControl)
    46.     {
    47.         laserConInput = (LaserbeamAction)input;
    48.  
    49.                    
    50.         if(laserConInput.select.wasJustPressed)
    51.         {
    52.             consumeControl(laserConInput.select);
    53.            
    54.             if(PrefabUtility.GetCorrespondingObjectFromSource(this.GetFirstGameObject(rayOrigin)).name != "Lightparent")
    55.                 {
    56.                     Selection.activeGameObject = null;
    57.                     Debug.Log("This is not selectable object.");
    58.                     return;
    59.                 }
    60.  
    61.             ControlObject = true;
    62.             Debug.Log("This is Light Object.");
    63.         }
    64.        
    65.         if(ControlObject == true && laserConInput.apply.wasJustPressed)
    66.         Debug.Log("Select Object was released.");
    67.            
    68.     }
    But it doesn't work with the error below.


    NullReferenceException: Object reference not set to an instance of an object
    UnityEditor.Experimental.EditorVR.Utilities.InputUtils.CollectDeviceSlotsFromActionMapInput (UnityEngine.InputNew.ActionMapInput actionMapInput, System.Collections.Generic.HashSet`1[UnityEngine.InputNew.DeviceSlot]& deviceSlots) (at Assets/EditorXR/Scripts/Utilities/InputUtils.cs:43)
    UnityEditor.Experimental.EditorVR.Core.EditorVR+Tools.SpawnTool (System.Type toolType, System.Collections.Generic.HashSet`1[UnityEngine.InputNew.InputDevice]& usedDevices, UnityEngine.InputNew.InputDevice device, UnityEngine.Transform rayOrigin) (at Assets/EditorXR/Scripts/Core/EditorVR.Tools.cs:206)
    UnityEditor.Experimental.EditorVR.Core.EditorVR+Tools+<>c__DisplayClass15_0.<SelectTool>b__0 (UnityEditor.Experimental.EditorVR.Core.EditorVR+DeviceData deviceData) (at Assets/EditorXR/Scripts/Core/EditorVR.Tools.cs:284)
    UnityEditor.Experimental.EditorVR.Core.EditorVR+Rays.ForEachProxyDevice (UnityEditor.Experimental.EditorVR.Core.EditorVR+Rays+ForEachProxyDeviceCallback callback, System.Boolean activeOnly) (at Assets/EditorXR/Scripts/Core/EditorVR.Rays.cs:340)
    UnityEditor.Experimental.EditorVR.Core.EditorVR+Tools.SelectTool (UnityEngine.Transform rayOrigin, System.Type toolType, System.Boolean despawnOnReselect, System.Boolean hideMenu) (at Assets/EditorXR/Scripts/Core/EditorVR.Tools.cs:244)
    UnityEditor.Experimental.EditorVR.ISelectToolMethods.SelectTool (UnityEditor.Experimental.EditorVR.ISelectTool obj, UnityEngine.Transform rayOrigin, System.Type toolType, System.Boolean despawnOnReselect, System.Boolean hideMenu) (at Assets/EditorXR/Scripts/Interfaces/FunctionalityInjection/ISelectTool.cs:28)
    UnityEditor.Experimental.EditorVR.Menus.MainMenu+<>c__DisplayClass80_0.<CreateFaceButtons>b__5 () (at Assets/EditorXR/Menus/MainMenu/MainMenu.cs:266)
    UnityEditor.Experimental.EditorVR.Menus.MainMenu+<>c__DisplayClass81_0.<CreateFaceButton>b__0 () (at Assets/EditorXR/Menus/MainMenu/MainMenu.cs:331)
    UnityEngine.Events.InvokableCall.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:166)
    UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:58)
    UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:66)
    UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:108)
    UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
    UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
    UnityEditor.Experimental.EditorVR.Core.EditorVR:Update() (at Assets/EditorXR/Scripts/Core/EditorVR.cs:425)


    I have an Action Map file for the code, but is there anything else I am missing?

    upload_2021-1-12_23-41-36.png
     
  2. Taiyo_no_gosaiji

    Taiyo_no_gosaiji

    Joined:
    Dec 10, 2020
    Posts:
    4
    What I needed to do was simply remove the unnecessary variable declarations and use var for the new variables.
     
  3. amirebrahimi_unity

    amirebrahimi_unity

    Unity Technologies

    Joined:
    Aug 12, 2015
    Posts:
    379
    Ahh...Glad you were able to figure it out. Which unnecessary variable declarations are you referring to though?
     
  4. Taiyo_no_gosaiji

    Taiyo_no_gosaiji

    Joined:
    Dec 10, 2020
    Posts:
    4
    The ActionMapInput I declared in line 18 of the code caused that error; I used it in line 47, so I added var to it.
     
    amirebrahimi_unity likes this.
unityunity