Update asset without re-creating it

Hello, I have a problem, when I update one of my asset I use

AssetDatabase.CreateAsset(dialogue, $"Assets/Resources/Dialogues/{fileName}.asset");
AssetDatabase.SaveAssets();

to update my asset, but for every gameobject who have the asset attach to it, the dialogue asset will be set to null, so I have to re-set the asset every time I edit it.

I was wondering if there’s a way to save the asset without re-creating it.

I suppose, that’s what causing it to reference to null, because when I go in debug mode in the inspector the “instance ID” and “the local identifier in file” change.

Don’t overwrite the dialogue asset – load it, change whatever, set dirty, save.

2 Likes

Doesn’t seems to work:

DialogueContainer dialogue = (DialogueContainer) AssetDatabase.LoadAssetAtPath($"Assets/Resources/Dialogues/{fileName}.asset", typeof(DialogueContainer));
dialogue.dialogueData = newDialogue.dialogueData;

EditorUtility.SetDirty(dialogue);

The asset indeed save but I still need to apply the asset to the script

Edit: Never minds, it’s working i just updated the wrong script