Creating assets in the Resources folder OnPostProcessScene will not be included in the final build

Hi,

I have a post process scene script that will create some textures based off the scene, and create high/low quality versions.

My process is;

  • I save these textures out to the resources folder using System.IO, then I import the textures via AssetDatabase.ImportAsset
  • I use the TextureImporter to modify some settings on the texture then I call SaveAndReimport
  • To be doubly sure I also do a call to AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport) when I finish

When I finish my build and try to load via resources, the files do not load and return null. For the next build, if I don’t clear my resources folder (which isn’t an option in the final solution I require), the textures are able to be loaded ok.

This leads me to believe the resources folder is built 1st. Is that correct, or is there something I am missing in the import process?

it is possible that the resources are built first, i am not really sure.
To solve your issue, and since there’s no callback for “pre build” to generate assets for that build, you can create a custom editor script for building your project. In this script, you can execute whatever code you like before the actual build starts.

BTW there’s the IPreBuildSetup, it’s meant to be used for tests, but who knows, maybe it can be used to run things before the build starts so it can help you in your case.

1 Like