- Home /
HideFlags not respected in batch mode
I am trying to run some editor scripts in the form of ScriptableObject subclasses from batchmode.
These ScriptableObject are getting unloaded prematurely via a call to Resources.UnloadUnusedAssets (called from BuildPipeline.BuildAssetBundles), resulting in the following error:
MissingReferenceException: The object of type 'Foo' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.
I had previously seen this error when running via the Editor Test Runner window (rather than batch mode). Setting hideFlags = HideFlags.DontUnloadUnusedAsset
fixed this, but it's reappears when I run from the command line in batchmode.
Why the different behaviour between batchmode and running within the editor? I am running the following command:
"C:\Program Files\Unity\Editor\Unity.exe" -batchmode -executeMethod My.App.Namespace.Start -logFile out.txt -buildTarget win64 -projectPath C:\Path\To\Unity\Project
. How can I get batchmode to acknowledge my object's hideFlags?
I was able to get this working in batchmode and editor mode by calling hideFlags = HideFlags.DontUnloadUnusedAsset
within OnEnable, rather than in the constructor of my ScriptableObject subclass. I'd still love to know the reason behind the different behaviour between editor and batchmode when setting hideFlags
from the constructor though!