Null prefab only in builds.

hersheys72

New member
Hi.
It works fine in Editor, but only recently it now is getting null when attempting to create a pickup item.

"The Prefab attribute value is null, please assign a default value or in the attribute, make sure the item XXX (1137463993) has a non-null value for attribute: PickupPrefab."

When attempting TryGetAttributeValue in AttributeCollection.cs, the Editor is successful in getting the value, whereas the build has a null m_Attributes in the AttributeCollection:TryGetAttribute call.
 
If "m_Attributes" is null, I'm wondering if the issue is that the items are not being initialized before you are trying to drop an item.

Could you double check that you have a InventorySystemManager in the scene and that it references the correct database.
Double check that the item in question is of that database and not another.
Double check that the InventorySystemManager and the item is beining initialized before the pickup drop.

If you are using the Addressables system make sure you aren't duplicating the itemDefinitions causing some desync between database and items. This can be an easy mistake to make if the definitions are not all in the same group.
 
Thanks for your response.

If "m_Attributes" is null, I'm wondering if the issue is that the items are not being initialized before you are trying to drop an item.
When I step through the code the items have to be initialized in the Item:TryGetAttributeValue before it tries to get the attribute values.
Could you double check that you have a InventorySystemManager in the scene and that it references the correct database.
Yes there is one, and it references the only one database.
Double check that the item in question is of that database and not another.
There is only one database.
Double check that the InventorySystemManager and the item is beining initialized before the pickup drop.
Yes it is initialized before the pickup drop.

If you are using the Addressables system make sure you aren't duplicating the itemDefinitions causing some desync between database and items. This can be an easy mistake to make if the definitions are not all in the same group

I dont believe this is the case. It is working fine in the Editor, just not in builds. The item definitions are all in the one database.
All of the items do register properly at the AddDatabase method. I put a log for each in the Initialize section of ItemCategory
 
Looking at the code I can't see how it would be possible for "m_Attributes" within the "AttributeCollection" class to be null if the item is initialized.
Are you sure that's what is null and not something else?
Can you check if the "Initialize" function of AttributeCollection is called?

Also what platform are you building to and with what settings?
Do you get any relevant warnings when building?
Can you confirm that you are not getting any errors (even unrelated ones) before have this error in your build?

Out of curiosity, is the prefab in question set as an Item Attribute or an ItemDefinition attribute?
Is your item Unique/Common Immutable/Mutable?
Also are you using the save system, and are you changing and saving that Attribute at runtime? (saving dynamic gameobjects is not possible out of the box, it requires some additional work).
 
Interestingly, when the database is initializing, through the AddDatabase call, the m_attributes is not null. This is output logs from the build.
AttributeCollection TryGetAttribute PickupPrefab, m_Attributes.Count: 8
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
Opsive.UltimateInventorySystem.Core.AttributeSystem.AttributeCollection:TryGetAttribute(String, AttributeBase&)
Opsive.UltimateInventorySystem.Core.AttributeSystem.AttributeCollection:CreateNewAttributesIfMissing(ListSlice`1)
Opsive.UltimateInventorySystem.Core.AttributeSystem.AttributeCollection:UpdateAttributesToMatchList(ListSlice`1, Boolean)
Opsive.UltimateInventorySystem.Core.ItemDefinition:UpdateAttributes()
Opsive.UltimateInventorySystem.Core.ItemDefinition:Initialize(Boolean, Boolean)
Opsive.UltimateInventorySystem.Core.InventorySystemManager:AddDatabase(IInventorySystemDatabase)
Opsive.UltimateInventorySystem.Core.InventorySystemManager:Initialize()
Opsive.UltimateInventorySystem.Core.InventorySystemManager:Awake()

Whereas this is the output on collision and we are trying to create the pickup, it is null

AttributeCollection TryGetAttribute PickupPrefab m_Attributes == null
UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
UnityEngine.Logger:Log(LogType, Object)
UnityEngine.Debug:Log(Object)
Opsive.UltimateInventorySystem.Core.AttributeSystem.AttributeCollection:TryGetAttribute(String, AttributeBase&)
Opsive.UltimateInventorySystem.Core.AttributeSystem.AttributeCollection:TryGetAttributeValue(String, T&)
Opsive.UltimateInventorySystem.Core.ItemDefinition:TryGetAttributeValue(String, T&, Boolean)
Opsive.UltimateInventorySystem.Core.Item:TryGetAttributeValue(String, T&, Boolean, Boolean)
Opsive.UltimateInventorySystem.DropsAndPickups.ItemObjectView:SetVisualInternal(Item)
Opsive.UltimateInventorySystem.DropsAndPickups.ItemObjectView:UpdateViews()
System.Action:Invoke()
Opsive.Shared.Events.InvokableAction:Invoke()
Opsive.Shared.Events.EventHandler:ExecuteEvent(Object, String)
Opsive.UltimateInventorySystem.Core.ItemObject:OnDisable()
UnityEngine.GameObject:SetActive(Boolean)
Opsive.UltimateInventorySystem.Interactions.InteractableBehavior:Deactivate()
Opsive.UltimateInventorySystem.DropsAndPickups.PickupBase:Deactivate()
Opsive.UltimateInventorySystem.DropsAndPickups.ItemPickup:Deactivate()
Opsive.UltimateInventorySystem.Interactions.InteractableBehavior:OnInteract(IInteractor)
System.Action`1:Invoke(T)
Opsive.Shared.Events.InvokableAction`1:Invoke(T1)
Opsive.Shared.Events.EventHandler:ExecuteEvent(Object, String, T1)
Opsive.UltimateInventorySystem.Interactions.Interactable:Interact(IInteractor)
Opsive.UltimateInventorySystem.Interactions.Interactable:Select(IInteractor)
Opsive.UltimateInventorySystem.Interactions.InventoryInteractor:SetSelectedInteractable(IInteractable)
Opsive.UltimateInventorySystem.Interactions.InventoryInteractor:AddInteractable(IInteractable)
Opsive.UltimateInventorySystem.Interactions.Interactable:OnTriggerEnterInternal(GameObject)
Opsive.UltimateInventorySystem.Interactions.Interactable:OnTriggerEnter2D(Collider2D)
 
Try to log the name and HashCode() of the ItemDefinition.
My suspition is that these are not the same ItemDefinitions reference.

You did not answer whether you were using the Addressable System or not.
A common mistake with the Addressables is exactly that about having duplicate references of the same asset in memory if the groups are not setup properly with the correct dependencies.
That would also explain why it would only happen in builds.
 
Yes we are using Addressables- which I believe are being used in the Editor and Build versions.
In the TryGetAttribute call I've put a check if not initialized then to call Initialize, and that seems to have fixed it.
 
Yes we are using Addressables- which I believe are being used in the Editor and Build versions.
In the TryGetAttribute call I've put a check if not initialized then to call Initialize, and that seems to have fixed it.
Be careful with that, if it is as I said and the hashcodes are not the same then you will get other issues in other places.
Some checks for knowing if items are equivalent will compare the ItemDefinition reference rather than the ID.
 
Hi Sangemdoko,
You are correct, other problems occurred related to inventory, and if anyone is reading this thread it is not recommended to try patch this issue yourself.
It ended up being the Addressables. Although we only have the one database, some of the scenes did need to be packed together for it to work properly.
Thanks for your help.
 
Last edited:
Top