How an instantiated ScriptableObject apply changes to the original ScriptableObject?

ScriptableObject origin = AssetDatabase.LoadAssetAtPath(path, typeof(ScriptableObject)) as ScriptableObject;
ScriptableObject so = ScriptableObject.Instantiate(origin);

//change so...

//how to apply so's changes to origin

EditorUtility.SetDirty(origin);
AssetDatabase.SaveAssets();

You’ll need to give your object a method that takes an instance of itself and update it’s own values:

public class MyScriptableObject : ScriptableObject
{
    public int SomeInt;
   
    public bool SomeBool;
   
    public void UpdateValues(MyScriptableObject myObject)
    {
        SomeInt = myObject.SomeInt;
        SomeBool = myObject.SomeBool;
    }
}

What I do for Editor stuff like this is:

If your Object is not a ScriptableObject or a MonoBehaviour, use EditorJsonUtility instead of JsonUtility. If you want to be able to undo the changes, call Undo.RegisterCompleteObjectUndo before calling FromJsonOverwrite.

I found a better choice:

EditorUtility.CopySerialized(so, origin);
//or EditorUtility.CopySerializedManagedFieldsOnly(so, origin);
2 Likes