Unity-Technologies/UnityDataTools

Usage from within Unity

hybridherbst opened this issue · 3 comments

I tried using these tools from inside Unity to analyze import artifacts and for build postprocessors of generated data, which to be best of my understanding fall under SerializedFile.

However, it seems that the app doesn't properly work with domain load and unload, after a first attempt I'm always getting
20220816-192134-APN1-Unity_FBNg

for subsequent tries.
Are there plans to get this to work?

I found a relevant comment in the UnityFileSystem constructor that leads me to believe this is a bug / not implemented:

static UnityFileSystem()
{
    // Initialize the native library.
    var r = DllWrapper.Init();
    HandleErrors(r);
            
    // TODO: should Cleanup be called by the AppDomain.Unload event or something else?
}

This seems to do the trick, instead of the static constructor:

[InitializeOnLoadMethod]
static void Init()
{
    var r = DllWrapper.Init();
    HandleErrors(r);
    AssemblyReloadEvents.beforeAssemblyReload += () => DllWrapper.Cleanup();
}

Thank you for reporting this. To be honest, I did not design the code to work inside Unity. I will see if I can find a way to fix it so it can work inside or outside Unity without any change.

The above is already enough to get it working in Unity! Could use an ifdef so that the functionality works both in and outside Unity.

Also, it would be interesting to have examples for parsing files with it – I was successfully able to parse many of the asset database artifacts, but I wasn't able to parse scene files, for example (as they seem to live inside memory, not on disk).