How to remove unneeded references (texture, audio) when doing headless server builds?

I’d like to remove some audio and texture/material references from scenes in headless server builds, to save ram when running servers. What’s the best way to do that?

I was thinking about doing it in PostProcessScene but I didn’t find a way to check if I’m building a headless build or not.

You can add conditional compilation symbols in project settings which could be used to cause code to compile or not. e.g. define HEADLESS, then do something like…

#if HEADLESS
// my code to do stuff when HEADLESS is defined
#endif

Now, I don’t know if PostProcessScene allows you to strip out assets, but if so then you could choose to strip them or not by using conditional compilation.

Another option would be to do something with assset bundles - just don’t load certain bundles when in headless mode.

You can potentially do something in PostProcessBuild as well, but again, I don’t know if you can cause assets to be stripped or not.

Hopefully that gives you enough info to do some more research.

I know this thread is quite old, but I stumbled upon an asset that does this exact thing for you.
It’s called Headless Builder, and it’s on the Unity Asset Store.