Updating display of ScriptableObject properties in inspector

When I create an instance of my custom ScriptableObject in the editor, some code in Awake will set certain properties based on finding a sprite asset with the same name. However, these changes do not show up in the inspector until I either run and stop the game, or restart Unity. Is there a way to make the changes show up straight away? I tried EditorUtility.SetDirty but it doesn’t help.

    public void Awake()
    {
        if (spriteRef == null)
        {
            var results = AssetDatabase.FindAssets($"{name} t:sprite");
            if (results.Length == 0)
                Debug.LogError($"Cannot find sprite with name '{name}");
            else if (results.Length == 1)
            {
                string guid = results[0];
                string path = AssetDatabase.GUIDToAssetPath(guid);
                spriteRef = AssetDatabase.LoadAssetAtPath<Sprite>(path);
                if (spriteSize == Vector2.one)
                {
                    spriteSize.x = spriteRef.texture.width;
                    spriteSize.y = spriteRef.texture.height;
                }
                EditorUtility.SetDirty(this);
                Debug.Log($"Set defaults for {name}");
            }
            else
                Debug.LogError($"More than one sprite with name '{name}!");
        }
    }

I have also tried SerializedObject with ApplyModifiedProperties and that didn’t help either.

    public void Awake()
    {
        if (spriteRef == null)
        {
            var results = AssetDatabase.FindAssets($"{name} t:sprite");
            if (results.Length == 0)
                Debug.LogError($"Cannot find sprite with name '{name}");
            else if (results.Length == 1)
            {
                string guid = results[0];
                string path = AssetDatabase.GUIDToAssetPath(guid);
                SerializedObject so = new SerializedObject(this);
                var spriteRefLocal = AssetDatabase.LoadAssetAtPath<Sprite>(path);
                so.FindProperty("spriteRef").objectReferenceValue = spriteRefLocal;
                if (spriteSize == Vector2.one)
                {
                    so.FindProperty("spriteSize").vector2Value = new Vector2(spriteRefLocal.texture.width, spriteRefLocal.texture.height);
                }
                so.ApplyModifiedPropertiesWithoutUndo();
                Debug.Log($"Set defaults for {name}");
            }
            else
                Debug.LogError($"More than one sprite with name '{name}!");
        }
    }

Probably because Awake isn’t being called when the SO is instanced.

Use Reset() instead, as is it’s purpose.

Awake is called following the creation of the ScriptableObject. It is also called when the user types in and submits the intended name of their ScriptableObject, which Reset is not. The filename in Assets is initially shown as ‘Data’, although a newly created scriptable object (before the initial rename) sees its own name as an empty string.

Interestingly, the view of the data in the inspector does update if I subsequently rename the SO. Awake runs again and the display updates immediately without needing to run and stop the game. But it doesn’t work on the initial rename, even though the data has actually been set. This may be to do with threads. On the initial rename, the output is as follows:

[Worker0] Set defaults for small_cloud_3

On a subsequent rename, the output is as follows:

Set defaults for small_cloud_3

Suggesting that on the initial rename, Awake is being called on a worker thread rather than the main thread.