Hey Everyone!
I’ve been having some headaches with Unity recently, mainly in related to changing player defines based on the importing/removing of components from the project. I’ve narrowed my issue down to where I’m setting static members to be a certain value in the OnPostprocessAllAssets() function, but then when that script reaches the function called by the [UnityEditor.Callbacks.DidReloadScripts] function, that varliable has been reset.
For some very basic code examples:
public class MyClass : AssetPostprocessor
{
static mybool = false;
static void OnPostprocessAllAssets (string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
//this is always called before OnScriptsReloaded()
mybool = true;
}
[UnityEditor.Callbacks.DidReloadScripts]
static void OnScriptsReloaded()
{
if(myBool) {
//this code is never reached, myBool always is false here
}
}
}
If anyone has any insight here on what I’m doing wrong, I’d love to hear it! Ideally, the myBool var will maintain its value across both functions.