For context: I’m working on a project wide scene management system. This isn’t quite literally to manage scenes in Unity, it’s actually for a loading screen.
I had some other issues which I manage to solve as I was working on the system (many order of execution issues, for example). At some point, I decided to make a build, just to test the system outside the editor, and for my surprise, the system didn’t work at all. It however, continued working on editor.
So I decided to make a development build and I put somewhere a Debug.Log() to see if I could get something. And well…
The system works this way: using this extension, I assign an SceneField type variable (called Loading Screen Scene) to the Scene Management inspector. The fields from the inspector are retrieved from a ScriptableObject called SceneManagementProjectSettings. The original fields are stored here.
Then, there’s the core code SceneManagement, which retrieves the values
from SceneManagementProjectSettings. Later on, the SceneManagement class raises the Init() method, where it calls the SceneManagementManager (very long name, I know) class and calls the method SetLoadingScene(SceneField scene). This method receives the already previously set field on the inspector. On the Loading process itself, Unity’s SceneManager class need to load Loading Screen Scene. Now, I obviously omitted lots of details, but that’s the basic structure.
The big issue comes when I build the project. According to the console message, it seems that the field Loading Screen Scene is set to null. For some reason, this doesn’t happen on the editor.
I did some research, and most of this cases boiled down to the order of execution. So I tried changing the Script Execution Order from the project settings with no luck. Honestly, I’m not even sure if that’s what they were referring to. It could be that, or the actual order I naturally set up while coding the system, but there doesn’t seem to be anything to change, or at least I didn’t find anything relevant to change in terms of order. I could be wrong.
Another thing I found while searching, was this pretty interesting comment on another post.
If I take what this comment says, then that would mean that my SceneField type field is getting nulled because of serialization.
If serialization is the case, then what are my options to solve it? Keep in mind that this structure that I’m using is based on the code structure of this particular asset (I actually could be misinterpreting the structure of its code). With my basic understanding of serialization, the only thing I could find was that the SceneManagementManager class was marked as Serializable. As far as I know, that means that it can be pass through Unity’s serialization process. So I’m really not sure what else can I do.
I attached the main codes of the system, the project settings scriptable, its editor, and the SceneManagement class. The SceneManagementManager doesn’t have anything that could help, it’s mainly code of the loading process.
Thanks in advanced.
7888651–1003936–SMProjectSettingsEditor.txt (1.71 KB)
7888651–1003939–SMProjecSettings.txt (1.2 KB)
7888651–1003942–SM.txt (2.03 KB)