Clearing Editor References when Building for Mobile

Ah, memory…

There are many cases where I need to load separate SD/HD assets based on device memory. This usually involves removing the asset reference altogether then using Resources.Load() to load the SD/HD asset.

My scene is getting less and less clean in the editor, because everything isn’t hooked up by asset. In most cases, I still have the asset directly (as a Texture2D or whatever), plus a strings for the corresponding Resources.Load() in the same script. Resources.Load() is just an alternative way to init the asset reference. If I forget to clear all these references each time I build, the asset gets included directly in the build, and the app runs out of memory on low-end devices.

Is there a way to invoke a script on build player where I can clear specific asset references, then restore them afterwards?

Thanks,
Alex

If you want to modify the build for a specific platform, I suggest you take a look at the Build Pipeline functions. That’s how we achieved building different assets for Mobile or Desktop.