ScriptedImporter with lengthy processing time

Hello,

I want to write a ScriptedImporter to load a voxel format I created (it’s an old format that I have lots of assets already made with). I would also like the ScriptedImporter to perform some calculations on the data that are fairly CPU-heavy (I want to raymarch the voxel objects to bake a custom ambient occlusion effect into them). However, I fear that these calculations won’t be preserved, and that the calculations will happen every time Unity is loaded (The ScriptedImporter is called every time a file is loaded, as far as I know). Is there any way I can ensure this data be stored in some way, perhaps by serialization in the generated .meta file that accompanies my custom file?

Thanks!

I don’t have any experience with the new ScriptedImporters, but after a cursory glance I don’t see what could stop you from storing associated data in your project and saving/loading that.

Something like this:

string path = Path.Combine(Application.dataPath, "Resources", "VoxelData");
string file = path + "unique identifer for your asset goes here";

if(File.Exists(file) == false)
{
   // data doesn't exist yet
   string data = GenerateVoxelData(object);

   File.WriteAllText(file, data);
   AssetDatabase.SaveAssets();
   AssetDatabase.Refresh();
}
else
{
   // data does already exist
   string data = File.ReadAllText(file);
   
   // do whatever
}