Search Unity

Option for mutable folders / data in a git package?

Discussion in 'Package Manager' started by toomasio, Nov 30, 2020.

  1. toomasio

    toomasio

    Joined:
    Nov 19, 2013
    Posts:
    198
    Hello,

    I am making an editor package where save data is stored based on what the user clicks on in the editor. Like a history.

    when I bring the git asset to another project, and modify the save data, I get this:
    Code (CSharp):
    1. The package cache was invalidated and rebuilt because the
    2.  following immutable asset(s) were unexpectedly altered:
    Is there an option to have some assets mutable in a git repo? For example, if I were to gitignore a Resources folder within the package, and store data in there that the user can alter.

    Or do I have to create an Assets/Resources/MyPackage/SaveData ?

    I would prefer to have these mutables folders right inside the package vs creating more folders in my other projects.

    Is this possible?

    Thanks,
     
    Last edited: Dec 1, 2020
  2. toomasio

    toomasio

    Joined:
    Nov 19, 2013
    Posts:
    198
    I have seemed to find a hack around this. I kept the .meta files in the package directories, pushed those to the repo...but I gitignored the individual files that I planned to mutate.

    This will only throw one yellow error per file on project startup, and it seems to still retain the save data without rebuilding the whole package directory everytime the project refreshes.

    Would still be nice if we could have a "Mutable" directory that Unity just ignores inside each package, please!
     
  3. Adrian

    Adrian

    Joined:
    Apr 5, 2008
    Posts:
    1,066
    Packages are considered immutable and live inside the Library folder. The Library folder is basically just a cache and is expected to be rebuilt from the Assets/ProjectSettings/UserSettings folders, if the project is e.g. checked out of version control or the Library folder is deleted.

    So the question is, is the data your storing project data that the user would expect to survive a rebuild of the Library folder? If so, it should live in the Assets folder. You could provide a setup step or include the data as sample for the user to import. I would also suggest to refer to the asset using its GUID, so users can move it anywhere in their project.

    Starting from 2020.1, if you want to store local user data that shouldn't be committed to version control, there's the new UserSettings folder. You cannot store normal assets in there but e.g. a JSON file.

    There's also the undocumented
    UnityEditorInternal.InternalEditorUtility.SaveToSerializedFileAndForget
    (and
    LoadSerializedFileAndForget
    ), which allow you to store assets outside of the Assets folder (e.g. in Library, ProjectSettings or UserSettings), if you don't want to serialize to/from JSON.
     
    toomasio likes this.
  4. toomasio

    toomasio

    Joined:
    Nov 19, 2013
    Posts:
    198
    Thanks @Adrian I will take a look into the usersettings folder.