UIS: Newbie Questions for Setup

meat

New member
hi, thank you so much for your support, but i feel im doing something fundamentaly wrong since my progress is stagnating since a week and i have tried to set it up multiple times (just copy the demo screen and build everything there, feel i generated to much technical debt, so i tried to set it up from scrach with the ui designer).

this may be lack of my programming skills but i realy dont seem to get simple things running even with your tutorials.

basicallay all i want to set up is a menu screen with an inventory and equipment which is different depending on whom i click,

this is the progress i got running so far:

im generating prefabs of my models at runtime and add to them via put the model in the right spot, PlayerUnit is the model prefab:

Code:
GoList.Add(Instantiate(PlayerUnit, playerSpawn.transform.GetChild(GoList.Count).GetChild(0).transform));
// go is GoList[GoList.Count - 1]
go.AddComponent<Inventory>();

go.GetComponent<Inventory>().AddItemCollection(IC);

where IC is just a id "eq" and the purpous is equipment

now when i select a go unit, i call this

Code:
Inventory.GetComponent<ItemViewSlotsContainerPanelBinding>().BindInventory(go.GetComponent<Inventory>());

Menu.GetComponent<DisplayPanelManager>().OpenPanel("Box Panel");

        // set equip to corect inventory

Equip.GetComponent<ItemViewSlotsContainerPanelBinding>().BindInventory(go.GetComponent<Inventory>());

Menu.GetComponent<DisplayPanelManager>().OpenPanel("Equipment Panel");



and i like to add an item while runtime, which i do like this (database is from the demo):


Code:
//list of items i create
SpawnedItems.Add(InventorySystemManager.CreateItem("Iron Sword"));

// add to last go unit which i have collected in GoList
GoList[GoList.Count - 1].GetComponent<Inventory>().AddItem(new ItemInfo((1, SpawnedItems[SpawnedItems.Count - 1])));


now when i open the Equipment and inventory tab i get alot of errors and i dont understand why


now the vast ammount of errors i get are:

"NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateInventorySystem.UI.Item.ItemViewSlotsContainer.Initialize (System.Boolean force) (at Assets/Opsive/UltimateInventorySystem/Scripts/UI/Item/ItemViewSlotsContainer.cs:39)"

which is directing me to this line of code:

Code:
UnitList.Add(Instantiate(PlayerUnit, playeSpawn.transform.GetChild(UnitList.Count).GetChild(0).transform));

which IS a instance since i am instanticating it!

then when i select the unit game object i get this error:

The inventory 'Prefab HeroUnit(Clone) (Opsive.UltimateInventorySystem.Core.InventoryCollections.Inventory)' does not contain an item slot collection for the ID provided in the ItemSlotCollectionView

now i tried to add as stated above IC is just equipable, and it dosent recognize it (why?)

i would realy be thankfull for any help, and i do understand that giving hints in the right direction helps learning, but im suck since a week now, and i dont see why this should be so complicated and unintuitive even though i have done the "tutorial" as in the videos,

so i would realy be thankfull for a simple line of code since this seems to be the issue,

* where i can create units at runtime (with that i mean adding an inventory and equipment slots which i can equip and unequip for each unit distinct, so that unit A und unit B have their own equipment and inventory)

where i can create items which do not give errors at runtime, (where i can assing an item in to the inventory)

and a inventory and equipment menu which works! at runtime!

i hope this dosent sound like a rant, but im kinda frustrated that im taking one week to get this running, and i feel this setup stuf should not take longer than an hour

thank you very much in advance!
 
Last edited:
I edited your questions to make it easier to read, I hope you don't mind (also next time please do use the code styling when pasting code in your question)

So you are doing a lot of things very differently from how we setup the Demo scene.

First of all do you have multiple players? If so I want to point out that each one of your character should probably have their own Inventory Canvas UI. Or if you have one main character (or main inventory) and other side characters, the the UI can be setup around the main character.

You spawn the character at runtime using a prefab. Why do you add the Inventory and Item Collection at runtime? Why not just add it on the character prefab directly?

The next thing you do is bind the Inventory to the to the container. That's where things go very wrong.
The Display Panel Manager probably hasn't been initialized yet because you spawned your character at runtime. The Display Panel Manager waits for a "Panel Owner" to be set before it can be initialized.

I would recommend you read those pages:

You shouldn't Bind, touch or open anything in the UI until you have the Display Panel Manager initialized with a Panel Owner (That's usually the player). Since you are spawning players at runtime you might find the Dynamic PanelOwner component to be quite useful.

The error you are getting is complaining about a null reference exception because of that.
I checked the code and it seems the error line does not match with my code anymore. I'll probably make an update to UIS soon since I fixed a few little bugs here and there (it should not be related to your issue though).

The last error you are getting mentions that the UI is trying to find the Item Slot Collection within your inventory to display your equipment but it can't find it. That might be because the ItemCollection you added on the inventory was not initialized, or because the name you specified in the UI does not match the one in the inventory. Or maybe it happens because the first error broke something.

A good way to setup the Equipment Panel is by using the UI Designer and setting the Inventory field to your character inventory. That will ensure that your ItemSlotCollection is setup correctly, if not you'll get a warning normally.

I would recommend you start first by getting the UI to work on one character that already exists in the scene. That should help you understand how the UI is setup.
Then the second step would be to remove your character and add it at runtime instead.
Once you got that working you can start looking in adding the UI for the secondary character(s).

If you go step by step you should be able to tackle one problem at a time as they come.

Let me know if you continue struggling with this and I'll try to help you however I can
 
Thank you very much for your quick replay! im going to answer some of your questions so you can maybe assest the situation better and have a look in to your suggestions at the same time - i was assuming that im doing things fundamentaly wrong ^^

I edited your questions to make it easier to read, I hope you don't mind (also next time please do use the code styling when pasting code in your question)
i dont mind, will be done in future!

So you are doing a lot of things very differently from how we setup the Demo scene.

First of all do you have multiple players? If so I want to point out that each one of your character should probably have their own Inventory Canvas UI. Or if you have one main character (or main inventory) and other side characters, the the UI can be setup around the main character.

i have one Player, but the player has multiple HeroUnits.

i have initialized the UI via the UI manager from scratch on an empty sceene, which i intend to additivly load in my world screen later on. so the sceen has a clean "Only UI and Inventory and some 3d Models" in it.

so i have the required "Game" component and the "Inventory Canvas" which i created via the UI designer

You spawn the character at runtime using a prefab. Why do you add the Inventory and Item Collection at runtime? Why not just add it on the character prefab directly?

easy! when i added it in to the prefab, i got an "Inventory ID already there" error or warning, and i incremented the inventory id automatically. in the scene when i was testing the id was set correctly, but the error still occured. is this the right way?

The next thing you do is bind the Inventory to the to the container. That's where things go very wrong.
The Display Panel Manager probably hasn't been initialized yet because you spawned your character at runtime. The Display Panel Manager waits for a "Panel Owner" to be set before it can be initialized.


the display panle manager is automatically set via the UI designer setup steps. this might be a reason why things are not working.

what i understand, the display panles are initialized with the corect content right? so my intention is to pass the current HeroUnit to the Panel Manager as the PanelOwner (in hopes that it correctly initializes all sub panels, this does not seem to work^^) so this was the initial intention, but the initial panel owner is set to an game object "main player" which is not an HeroUnit but the game controler and has an inventory and an id which is 0, i was thinking to use this as an intermediat inventory later.

I would recommend you read those pages:

i have but i will do it again!

You shouldn't Bind, touch or open anything in the UI until you have the Display Panel Manager initialized with a Panel Owner (That's usually the player). Since you are spawning players at runtime you might find the Dynamic PanelOwner component to be quite useful.

ok so untill here i assume that an wrong initialization is the reason, but as i said, the initialization is done via Setup from the UI Manager

The error you are getting is complaining about a null reference exception because of that.
I checked the code and it seems the error line does not match with my code anymore. I'll probably make an update to UIS soon since I fixed a few little bugs here and there (it should not be related to your issue though).

The last error you are getting mentions that the UI is trying to find the Item Slot Collection within your inventory to display your equipment but it can't find it. That might be because the ItemCollection you added on the inventory was not initialized, or because the name you specified in the UI does not match the one in the inventory. Or maybe it happens because the first error broke something.

ok this sounds good, so i have basically just added an ItemCollection game object in the inspector with "eq" and Equipment set, must i call an additional init or should i do this via code?

A good way to setup the Equipment Panel is by using the UI Designer and setting the Inventory field to your character inventory. That will ensure that your ItemSlotCollection is setup correctly, if not you'll get a warning normally.

as i said :)

I would recommend you start first by getting the UI to work on one character that already exists in the scene. That should help you understand how the UI is setup.
Then the second step would be to remove your character and add it at runtime instead.
Once you got that working you can start looking in adding the UI for the secondary character(s).

If you go step by step you should be able to tackle one problem at a time as they come.

ok thx, ill try to go through it again

Let me know if you continue struggling with this and I'll try to help you however I can
 
i have initialized the UI via the UI manager from scratch on an empty sceene, which i intend to additivly load in my world screen later on. so the sceen has a clean "Only UI and Inventory and some 3d Models" in it.

so i have the required "Game" component and the "Inventory Canvas" which i created via the UI designer
That sounds good I do the same thing for the Adventure Kit I am working on.

easy! when i added it in to the prefab, i got an "Inventory ID already there" error or warning, and i incremented the inventory id automatically. in the scene when i was testing the id was set correctly, but the error still occured. is this the right way?
Ok so that's the first problem you should solve. The Inventory Identifier is a component that lets you identify your inventories when they are unique. it's a great way for you UI to find the player inventory.
If you are getting an error that must mean you have two gameobjects that have an Inventory Identifier and they are both trying to have the same ID.
Are you perhaps spawning the same prefab multiple times? You should spawn the player character only once such that you do not try to set a new game object with the same inventory Identifier ID.

Note the the Inventory Identifier is its own component it is not the Inventory component.

the display panle manager is automatically set via the UI designer setup steps. this might be a reason why things are not working.

what i understand, the display panles are initialized with the corect content right? so my intention is to pass the current HeroUnit to the Panel Manager as the PanelOwner (in hopes that it correctly initializes all sub panels, this does not seem to work^^) so this was the initial intention, but the initial panel owner is set to an game object "main player" which is not an HeroUnit but the game controler and has an inventory and an id which is 0, i was thinking to use this as an intermediat inventory later.
Ok Things start to make a bit more sense.

So you have a master Inventory and then a Hero Unit inventory for each character that the player can control, right?
In that case the panel owner should be the master inventory.
I'm guessing the ID clash has to do with the main inventory identifier ID from the character instance clashing with the master inventory ID, make sure they are different.

ok this sounds good, so i have basically just added an ItemCollection game object in the inspector with "eq" and Equipment set, must i call an additional init or should i do this via code?
You shouldn't have to initialize anything via code, it should be all automatic when things are correctly setup.

My guess is that the UI is trying to find the ItemSlotCollection but it is looking on the master inventory instead of the hero unit inventory and that's why it's not finding it.

Like you mentioned in your first post, this should work (of course as long as the ItemViewSlotsContainerPanelBinding reference is correct):
Code:
m_ItemViewSlotsContainerPanelBinding.BindInventory(go.GetComponent<Inventory>())


Feel free to send a video using streamable.com or some screenshot of how you've set things up. It should help me understand what you are doing in more depth.
 
good news everyone! i fixed the issue, it was a combination of different unrelated bugs and an bad read of variables. lessons learned: the panel owner is meant to be the controler of the panels, (only relevant in multiplayer as far as i can tell) and trying to directly manipulate inventory identifier variables is a bad idea. and explicitly setting the itemSlotCollection and ItemCollection in the equipment panel was hidden there as well ^^
 
That's great news!
I hope things get smoother now that you have a good understanding on the Panel system.
Don't hesitate to go through the video tutorials and the documentation to refresh your memory when you are unsure about something.
And if you struggle with anything else feel free to open another forum thread :)
 
Top