UnityTechnologies / InputSystem_Warriors

Example Project for the new Unity Input System
563 stars 128 forks source link

playerInput.devices[0] NullReferenceException: Object reference not set to an instance of an object #12

Open nkzhenhua opened 2 years ago

nkzhenhua commented 2 years ago

playerInput.devices[0] is accessed before the player setup is done. The error is triggered in PlayerController.OnControlsChanged before the SetupPlayer() is called.

NullReferenceException: Object reference not set to an instance of an object DeviceDisplayConfigurator.GetDeviceName (UnityEngine.InputSystem.PlayerInput playerInput) (at Assets/Scripts/Utilities/DeviceDisplayConfigurator.cs:33) PlayerVisualsBehaviour.UpdateUIDisplay () (at Assets/Scripts/Behaviours/Player/PlayerVisualsBehaviour.cs:49) PlayerVisualsBehaviour.UpdatePlayerVisuals () (at Assets/Scripts/Behaviours/Player/PlayerVisualsBehaviour.cs:41) PlayerController.OnControlsChanged () (at Assets/Scripts/Behaviours/Player/PlayerController.cs:91) UnityEngine.Events.InvokableCall.Invoke () (at <82c503977c5347cf82f44677f633fcf6>:0) UnityEngine.Events.UnityEvent`1[T0].Invoke (T0 arg0) (at <82c503977c5347cf82f44677f633fcf6>:0) UnityEngine.InputSystem.PlayerInput.HandleControlsChanged () (at Library/PackageCache/com.unity.inputsystem@1.2.0/InputSystem/Plugins/PlayerInput/PlayerInput.cs:1806) UnityEngine.InputSystem.PlayerInput.OnEnable () (at Library/PackageCache/com.unity.inputsystem@1.2.0/InputSystem/Plugins/PlayerInput/PlayerInput.cs:1660)

Assets\Scripts\Utilities\DeviceDisplayConfigurator.cs(87,20): warning CS0472: The result of the expression is always 'true' since a value of type 'bool' is never equal to 'null' of type 'bool?'