Search Unity

Asset changes not updating the updates in the file even they appears in the inspector

Discussion in 'Editor & General Support' started by sachaamm, May 11, 2021.

  1. sachaamm

    sachaamm

    Joined:
    Apr 11, 2016
    Posts:
    45
    I'm generating my asset files via the AssetDatabase API. One file is not getting changes updated, even the method AssetDatabase.SaveAssets() is called. I use also AssetDatabase.Refresh()

    1. Generating an scriptable object asset ( AssetDatabase.CreateAsset )

    2. Updating the scriptable object asset and try to save changes in the asset database ( AssetDatabase.SaveAssets )

    RESULT : The scriptable object asset is modified in the inspector, but in the file, the value wasn't changed. The value observed was : Target Strategy. TargetStrategy was updated from Self ( = 3 ) to Enemy ( = 5 ). When I close Unity and restart the editor, the file changes are lost. I also tried to use "SaveProject". This is probably a cache error


    Unity_yTgTZkNz7L.png notepad++_Ngvej4oPuT.png
     
    Last edited: May 11, 2021
  2. sachaamm

    sachaamm

    Joined:
    Apr 11, 2016
    Posts:
    45
    I guess Unity is not handling Polymorph Serialization. ( I didn't mentioned that I serialize Polymorph assets, basically child classes that are heritating a scriptable object class ) I just need to hard-recreate ( erase, create, and reference the new element created ) the asset. AssetDatabase.SaveAssets() just don't work, and I'm facing an editor bug where inspector values and assets files does'nt match. TDD_Step_Diagram.png
     
  3. That is correct. If you don't mind using 3rd-party, but Unity Partner solution I recommend Odin Serializer. It is free (not the same as the Odin Inspector!) and available even from GitHub.
    It is capable of serializing polymorphic structures.

    In case you want to take a look:
    https://odininspector.com/odin-serializer
    https://github.com/TeamSirenix/odin-serializer
     
    sachaamm likes this.
  4. sachaamm

    sachaamm

    Joined:
    Apr 11, 2016
    Posts:
    45
    Thanks, I will check. I found a turnaround of the issue, not quite elegant, i just erase and recreate the file. Do you know by chance if Odin can handle scriptable objects ? because in my case i need persistance and save config files. in any case i can save it with JSON Serialization but I want to rewrite my codebase the least as possible .