Search Unity

How to avoid rewriting the value of ScriptableObject at runtime in editor?

Discussion in 'Addressables' started by kyubuns, Feb 4, 2021.

  1. kyubuns

    kyubuns

    Joined:
    Aug 6, 2013
    Posts:
    138
    When the Play Mode Script is "Use Asset Database" or "Simulate Groups", the Addressables. If you make changes to a ScriptableObject loaded using LoadAssetAsync<T>, the changes will remain in the Editor.
    Of course, this phenomenon does not occur when building on the actual device or when "Use Existing Build" is selected.
    Is there a way to make changes to a ScriptableObject without leaving changes in the Editor?

    If this problem without Addressable, you can just Instantiate it with Object.Instantiate.
    However, when I modify a ScriptableObject named "A" and load a "B" that references "A", I want it to use the modified "A".

    The behavior on the real machine and "Use Existing Build" works as I expected, but when I do it in the editor, the diff appear every time.
    Is there anything I can do?
     
  2. kyubuns

    kyubuns

    Joined:
    Aug 6, 2013
    Posts:
    138
    This is the code I'm running.

    Code (CSharp):
    1. IEnumerator Start()
    2. {
    3.     Debug.Log("Start");
    4.  
    5.     var baseFontLoader = Addressables.LoadAssetAsync<TMP_FontAsset>("Font/Base");
    6.     yield return baseFontLoader;
    7.     var baseFont = baseFontLoader.Result;
    8.  
    9.     var language = "japanese"; // In fact, load it from settings.
    10.     var additionalFont = "";
    11.     if (language == "japanese") additionalFont = "Font/Japanese";
    12.     if (language == "chinese") additionalFont = "Font/Chinese";
    13.     if (!string.IsNullOrEmpty(additionalFont))
    14.     {
    15.         var fallbackFontLoader = Addressables.LoadAssetAsync<TMP_FontAsset>(additionalFont);
    16.         yield return fallbackFontLoader;
    17.         baseFont.fallbackFontAssetTable.Add(fallbackFontLoader.Result);
    18.     }
    19.  
    20.     yield return Addressables.InstantiateAsync("TestCanvas"); // Reference to Font/Base
    21.     yield return Addressables.InstantiateAsync("TestCanvas2");
    22.  
    23.     Debug.Log("Finish");
    24. }
     
  3. AriyaSD

    AriyaSD

    Joined:
    Nov 2, 2019
    Posts:
    24
    Maybe try calling Resources.UnloadAsset on your ScriptableObject when exiting play mode. That should discard any change you make.
     
    kyubuns likes this.
  4. kyubuns

    kyubuns

    Joined:
    Aug 6, 2013
    Posts:
    138
    Thank you!
    My problem has been solved!