Hey everyone,
I’m running 2022.2.7f1 and experiencing an issue with what I believe is DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups
. I have a number of systems that I create manually in a bootstrap, each with logic and dependencies in OnCreate. In editor, everything works great. Hit play, and everything works. The strange thing is that in a Windows build, I get all sorts of errors from the OnCreate methods where objects aren’t initialized, etc.
I am using abstracts and some amount of reflection, which I know can be stripped in certain cases. For all of those cases, however, I have decorated with [UnityEngine.Scripting.Preserve]
. Is something else being stripped? Or are abstracts and things unsupported?
To the next poor soul that runs into this:
The solution to this was to remove a level of nesting in my types.
I went from: SystemA : SystemB<T> : SystemC<T> : SystemBase
to: SystemA : SystemB<T> : SystemBase
Having B and C separate was a bad idea anyway, and condensing them together allowed DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups
to perform as expected.
It seems as though reflection was also an issue here. I’m initializing variables at various levels of system nesting during the bootstrap using reflection, and no matter what I did, couldn’t get the build to perform the same way as the editor. I know that reflection causes headaches with build stripping but no combination of [Preserve]
, or [assembly: UnityEngine.Scripting.Preserve]
seemed to help.
In the end, I had to explicitly enumerate over all system.GetType().BaseType
s to get it to function properly.