Why is it so difficult to programmatically use UIS at runtime?

spryx

New member
I've tried and failed multiple times to get UIS setup. I don't have a player object that exists prior to runtime but instead instantiate one when the scene is ready. Without going into specific details, I have no way to avoid this. The player must be created AFTER the scene is loaded.

On run, I get thousands of the same exception obviously related to player input:

NullReferenceException: Object reference not set to an instance of an object
Opsive.Shared.Input.UnityInput.GetButtonInternal (System.String buttonName) (at Assets/Opsive/Shared/Input/UnityInput.cs:195)
Opsive.Shared.Input.PlayerInput.GetButton (System.String buttonName) (at Assets/Opsive/Shared/Input/PlayerInput.cs:142)
Opsive.UltimateInventorySystem.Input.SimpleInput.CheckInput (Opsive.Shared.Input.PlayerInput playerInput) (at Assets/Opsive/UltimateInventorySystem/Scripts/Input/SimpleInput.cs:81)
Opsive.UltimateInventorySystem.UI.Panels.DisplayPanelManagerHandler.Update () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Panels/DisplayPanelManagerHandler.cs:120)

Player prefab:
1653945011553.png
 
I think you are missing the "Dynamic Panel Owner" component.

I added this page in the documentation which hopefully should help:

The errors you get are related to the Display Panel Manager Handler checking for input even though it is null.
That shouldn't be happening since the component should be disabled until a panel owner is set.

So perhaps there is something I'm missing from your setup.

I'm not sure if this is related but someone had similar questions: https://opsive.com/forum/index.php?threads/uis-newbie-questions-for-setup.5458/#post-26853
Maybe that helps.

I'll add more to the documentation page if you find more relevant things to mention
 
That seems to fix one problem when I added dynamic inventory. I can at least open the menu. I still seem to be having issues with input. See above exception. When I open the inventory, I get:
NullReferenceException: Object reference not set to an instance of an object
Opsive.Shared.Input.UnityInput.GetButtonDownInternal (System.String buttonName) (at Assets/Opsive/Shared/Input/UnityInput.cs:230)
Opsive.Shared.Input.PlayerInput.GetButtonDown (System.String buttonName) (at Assets/Opsive/Shared/Input/PlayerInput.cs:157)
Opsive.UltimateInventorySystem.UI.Grid.GridBase.Update () (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Grid/GridBase.cs:261)

Spammed. Is this package using the new input system? It seems like we are checking input for a controller (I don't have one connected).
 
Looking at the code the error is pointing to, It would seem your "UnityInput" component did not get initialized before you try using it. It gets initialized on Awake so you must add it somewhere where it can be enabled before you start using the UI.

Usually the UnityInput component is set on the player character gameobject. At least next to or assigned to the ItemUser component.

The UnityInput component uses the built-in Input Manager. If you which to use other input systems: new Input system, Rewired, InControl, etc.. you can check out our integrations with those. All it requires is replace the UnityInput component by its respective integration component.

I hope that helps
 
Top