UIS Losing Prefab References In Inventory Manager?

mattmirrorfish

New member
hey there, I'm seeing a behavior where periodically UIS will lose references to prefabs in the Inventory Manager. I've set the values about 4 or 5 times now and then saved to try to trigger an asset database save in Unity, but it just seems to drop them. Here's a screenshot of the lost references. I think it's around times when I'm entering playmode, or at least that's when I notice it.

f21318658c96296c89240ba438c2595f.png


Edit: I noticed someone else mention some issues with Odin, I'm running Odin as well. I wonder if there's a potential serialization conflict between UIS and Odin?
 
Last edited:
I'm not really sure how Odin could be affecting our serialization process, I don't know how it works behind the scenes.

First I would like to confirm you are indeed referencing prefabs directly from the asset view and not from within a scene. prefabs inside a scene are considered game objects and cannot be referenced by scriptable objects.

If you are sure that you are referencing the prefabs correctly then please let me know your Unity Version that you are using and I'll try to replicate the issue. I don't own Odin, so I won't be able to test it with that though, we'll see if it's not something unrelated first
 
Thanks for your reply. Unity version is 2020.3.1f1 as shown in screenshot above.

I am referencing prefab assets that in this case are placeholders and never used in a scene or anywhere else. I need them there because apparently equipped doesn’t work without them. They are assigned at the category level and inherited by all equipment. I’d say this happened about 20 times yesterday, usually detected upon entering play mode when the console throws an null ref.
 
I was able to replicate the issue in Unity 2020.3.0f1, 2020.3.9f1 and 2019.4.
So it seems that the issue is not related to the unity version, it was just very inconsistent so I never noticed it.

I could get the issue on any attribute type, not just the GameObject type.

I could get the issue for Category Attributes. For ItemDefinition attributes I could only get the issue when no ItemDefinition was child of that category, so at least it reduces the error scope.

Having a look at things in more detail I believe the issue happens when you come out of play mode while having the Inventory Manger category Editor openened.

The attribute value is changed, but for some reason the attribute displayed in the editor is no longer the same as the one in the category.
most likely I deserialized the categories when entering play mode but when refreshing the Attribute list I do not get the updated attributes and instead keep the "old" ones.

I'm still looking into how I'll fix that. Either I'll redraw the correct attributes when the editor is selected after play mode, or I'll get the current attribute the moment the value is changed or when the attribute in the list is clicked.

As soon as I have a fix I'll send it to you here
 
In the ItemCategoryManager and the ItemDefinitionManager script add those two lines when an attribute is selected:
Code:
//Make sure to refresh the attribute in case the object was deserialized again.
ShowAttributeTab(m_AttributeCollectionsTabToolbar.Selected);

In the ItemCategoryManager it should be on line 202
In the ItemDefinitionManager is should be on line 132

It should look something like that:
Code:
}, null, (int index) =>
{
    //Make sure to refresh the attribute in case the object was deserialized again.
    ShowAttributeTab(m_AttributeCollectionsTabToolbar.Selected);
    m_AttributeVisualElement.BindAttribute(m_AttributesReorderableList.ItemsSource[index] as AttributeBase);
}, () =>
{

That should force the attribute to be the correct one when it is selected.

Also just to be extra sure in the AttributeVisualElement script replace the AttributeChanged function:
Code:
/// <summary>
/// Saves the changes and triggers the value changed event.
/// </summary>
private void AttributeChanged()
{
    ItemCategoryEditorUtility.SetItemCategoryDirty(m_Attribute.AttachedItemCategory, true);
    if (m_Attribute.AttachedItemDefinition != null) {
        ItemDefinitionEditorUtility.SetItemDefinitionDirty(m_Attribute.AttachedItemDefinition, true);
    }
    if (m_Attribute.AttachedItem != null) {
        AttributeEditorUtility.SerializeAttributes(m_Attribute.AttachedItem);
    }
    Refresh();
    OnValueChanged?.Invoke(m_Attribute);
}

After those changes the issue seemed to go away. Please let me know if those work for you too.
 
Actually I've been experiencing extreme slowness in the Editor since that change.
So ignore the second change of the AttributeChanged function. The first change should be the one that fixes the issue.
 
Top