- Home /
Get name of Scene-file from MonoBehaviour
I'm making a game with lots of additive scene loading. When I have a scene loaded, I can't seem to find a way to get the scenefile-name from a Component (MonoBehaviour) on a GameObject in it. Is that possible?
I can't use SceneManager.GetActiveScene() because the Component that asks is not necessarily in the active scene.
I would prefer a solution, that works both when playing the game in UnitiyEditor and in builds. If that's not possible, a solution for playing the game in UnityEditor is most important. Runtime I can keep track of what's loaded somehow.
Any input would be most valued! :-)
Answer by HafizAli · Jun 27, 2017 at 09:11 AM
I think this is what you are asking http://answers.unity3d.com/questions/747603/how-does-dontdestroyonload-work-1.html
Thanks for the answer! But it's something else I'm after... I'll try to be more clear:
I have an EnvironmentChunk in a scene. At some points that EnvironmentChunk knows it's time to unload and load another EnvironmentChunk (also a scene). At that point, I want the EnvironmentChunk to call a Game$$anonymous$$anager (which is indeed DontDestroyOnLoad), and say unload me ("I'm this scene file") and load this other one.
$$anonymous$$y current workaround is having a public string in the EnvironmentChunk with the scene file name in it. It's a hell, when rena$$anonymous$$g scenes... that's why I'm searching for a better solution :-)