Using [ShowInInspector] on ScriptableObject does clear the reference in the inspector on clicking play.

Issue #302 resolved
Former user created an issue

Reproduce:

  1. Create a class deriving from ScriptableObject:

[CreateAssetMenu] public class ItemData : ScriptableObject { [SerializeField] private string value;

public string Value
{
    get { return value; }
}

}

  1. Create a class deriving from MonoBehavior that holds a reference for the ItemData and expose it in the inspector using [ShowInInspector]: public class ItemCollection : MonoBehaviour { [ShowInInspector] private ItemData itemData; }

  2. Create the actual Asset for ItemData by right-clicking in the Project Window and going to "Create/Item Data"

  3. Assign the ItemData Asset to the ItemCollection field in the inspector by drag and drop.

  4. Hit Play.

Result: Reference to the ItemData ScriptableObject set in the inspector gets cleared and set to null.

Expected: This works totally fine when using [SerializeField] in the item collection instead of [ShowInInspector] so this should be expected working the same way.

Using: Unity 2017.3.0f3 Odin 1.0.7.0 Window 10 Pro 10.0.16299

Fresh Project Only Odin imported

Comments (3)

  1. mSkull001

    I've deleted the attached zip file because it contained the Odin Inspector package, and you're not allowed to redistribute that.

  2. mSkull001

    Your issue here is that you're not serializing ItemData field in your MonoBehaviour - ShowInInspector will only make it show up in the inspector. This allows you can have values that are visible and editable in the inspector (fx for debugging purposes) without saving any changes to the object.

    To fix this, just replace the ShowInInspector attribute with the SerializeField attribute, and then everything should work as expected :)

  3. Log in to comment