Skip to content

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

@nkzhenhua

Description

@nkzhenhua

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?'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions