Unity losing reference of externally modified ScriptableObjet in Editorscript

Hello.

There is an issue with the editor tool i am working on. I am creating and editing scriptable objects trough tool’s working pipeline and there is a bug.

For example

on editor scripting there is a line like that

targetObject.part = (Part)EditorGUILayout.ObjectField(targetObject.part,typeof(Part),false);

after making changes on that “ScriptableObjet” i am calling EditorUtility.SetDirty( targetObject.part ) and saving it.

That allows to asset showing diff’s on sourcetree. When i reset that diff. Or open that scriptable objet on a text editor and change a variable value. It looses reference in this line

targetObject.part = (Part)EditorGUILayout.ObjectField(targetObject.part,typeof(Part),false);

When i press to the play button or reload any script it shows up again without any problem.

I tried AssetDatabase.Refresh();

Thanks

I found a workaround. Unity destroys the object after reimport process. So Object == null expression is being true. But it is not null exactly. You can get its instance id so i made a safety check like this

 public void CheckPart(int index) {
        try {
            if(bodies[index] == null) {
                int instId = bodies[index].GetInstanceID();
                string path = UnityEditor.AssetDatabase.GetAssetPath(instId);
                bodies[index] = UnityEditor.AssetDatabase.LoadAssetAtPath<BodyVisualAsset>(path);
            }
        }
        catch(System.NullReferenceException) {
            bodies.RemoveAt(index);
        }
    }