UnityTechnologies / InputSystem_Warriors

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

fix the playerinput.devices[0] references issue #13

Open nkzhenhua opened 2 years ago

nkzhenhua commented 2 years ago

Fix the issue: https://github.com/UnityTechnologies/InputSystem_Warriors/issues/12: playerInput.devices[0] is accessed before the player setup is done. The error is triggered by 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)

Fix the build warning: 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?'

gd-evans commented 2 years ago

Any chance to get this merged in? We're seeing the same issue, and are unable to use the project in this state.