UIS + Addressables

airoll

Member
I am trying to get set up with Unity Addressables and I had a question about how it might work with UIS. I perused some past threads and compatibility seemed questionable.

Right now, I have a Prefab object that contains the following components.

1662700150214.png

If I drag this prefab into a scene, the inventory database is set and everything works fine. However, if I try to load this prefab using AssetReference.InstantiateAsync(...), I get the following warning.

"The database is null, please specify one in the Inventory System Manager."

Is there any way to make the database loadable using Addressables? I have tried putting the database into the same group as well as its own addressable group, but nothing seems to fix this issue.
 
I am unsure about this since I haven't used the adressables system that way before.

I understand the benefit of using the Addressable to load and unload objects such that they are loaded only when you need them.
But these managers are suposed to be spawned once at the beginning of the game and never removed.

As for why the Database is considered null when using InstantiateAsync, perhaps because the database isn't loaded by the time prefab is spawned, or the other possibility is that the database is gettings dupplicated (I now this is a common issue when using addressables with scriptable objects), causing the Inventory System Manager to reference the scriptable object that is not loaded, since the loaded one is a duplicate instance with a different reference.

When you add the database in the addressable group do make sure to add All ItemDefinitions, Categories, etc... with it. And only use a single group for all of that to make sure they do not get dupplicated having multiple reference to the same object.

The place where you could use the Addressable to your advantage is within Item/Definition/Category Attributes. To load icons, models, etc...
Note that our system and UI are all Instant, so they do not support asynchrounous loading by default. But with a few custom ItemViews and UI it is possible to setup.


Also, just to be sure the issue is because of the asynchrounous nature of the function you can try to instantiate synchrously. I believe the latest version of the Addresable allows you to do that.
 
Okay I think I figured out what was happening, but I'm not exactly sure why. Perhaps you can help!

I modified the InventorySystemManagerInspector to not hide the m_Database field. When that happened, it turned out that:

1662781189523.png
The Database field was set to None. I had to then manually set this field to the database and it assigned it properly. Then when I loaded the prefab the database was set properly. (See below for the state after I set the field.)

1662781161271.png

For whatever reason, if I try to modify the Database (with the Update Scene button), it does not persist the set database in my prefab. I'm not sure exactly why this is, but would love to understand if you might understand better what's going on here!
 
Okay after looking at it some more something else is wrong. When I instantiate prefabs that have an inventory, the inventories look like this:

1662787949685.png

If I inspect the item collection, all the items look fine at this point.

Then when I inspect the items when I unload the scene, I get the warning: "Item was removed from an Item Collection which was not set on the item." When I inspect the ItemInfos in the inventory, it looks like they have a null item.

1662788044750.png

I did as you suggested, which was to add all ItemDefinitions, Categories, etc. to a single group. Am I missing something here? Is something being unloaded first that would cause all the items and item definitions to become null?
 
Last edited:
... My guess is that the ItemDefinitions in the Inventory are not not loaded anymore. Either because it doesn't know about the addressable reference, or because the ItemDefinition was not loaded before the prefab with the Inventory was.
Keep in mind the Inventory is directly referencing the ItemDefinition. It is not using an Addressable reference of the ItemDefinition. Perhaps making a custom Inventory that uses Addressable references could work.... but I'm not sure.

Like I said previously, the inventory system was not built with asynchrous loading in mind. So the best way to go about it is probably not using the Addressable system for the database, itemDefinitions, etc... and instead just use it for the attributes inside the ItemDefinition, Items, etc...

For the next major update I'll investigate Addressables further to see if I can come up with a better solution. But unfortunatly that won't be any time soon. I know some people have used it with UIS but I'm not sure to what extent.
 
Hey quick update here: the bugs actually originated from using "Using Existing Build (Android)" in Editor, which caused some issues. It actually completely worked fine. I added all ItemDefinitions, Categories, etc. to a single Addressables group. Happy to provide more details in the future!
 
That is great news :)
Yes do keep this thread updated with any issues and tips you have, I'm sure it will be very useful to anyone trying to do the same
 
Top