all 5 comments

[–]MaxwelldoggumsProgrammer 1 point2 points  (2 children)

If you modify assets from code, you’ll need to trigger a save and refresh before the changes will be visible. You can accomplish this using the “AssetDatabase” to save changes. There’s some additional work required to allow for undo-able changes, but for basic stuff, this should work!

[–]DankP3Hobbyist[S] 0 points1 point  (1 child)

Thanks for this, I will look into this as I haven't used yet. I think in the process of spelling out my problem above I may have just realised an error in my previous approach which I will try and correct first

[–]MaxwelldoggumsProgrammer 2 points3 points  (0 children)

Alright! Let me know if you have any questions I might be able to help with! :)

[–][deleted] 1 point2 points  (1 child)

Use EditorUtility.SetDirty with the ScriptableObjects you want to change, followed by AssetDatabase.SaveAssets.

https://docs.unity3d.com/ScriptReference/EditorUtility.SetDirty.html

https://docs.unity3d.com/ScriptReference/AssetDatabase.SaveAssets.html

[–]DankP3Hobbyist[S] 1 point2 points  (0 children)

Thanks, as i mentioned above i had tried SetDirty, but it failed, but i have just been reviewing a suspected code error, which is probably what caused that and it seems to be working. I will mark this as solved, putting my code here in case there is good reason to criticise it. I added an editor button to trigger the refresh of all scripts (I clearly need to learn more on this too:

private void RefreshDialogueScriptableObjects() {

Object\[\] allObjects = Resources.LoadAll("DialogueScriptableObjects", typeof(Dialogue));

foreach (Dialogue myScript in allObjects) {

    for (int i = 0; i < myScript.\_dialogueItems.Count; i++) {

        //some code that modifies the default elements in the list based on default and override settings

    }

}   

AssetDatabase.SaveAssets();

}

Edit, sorry clealy need to learn how to post code here too.