-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The manager doesn't unload a scene #48
Comments
Hey @VirtualMaestro thank you again for your report. This version is not stable yet, I'm working out on a new set of features towards v4, so these pre-releases might not fully work in the meanwhile. I'll keep you posted. |
The version private static readonly string LoaderScenePath = "Assets/Client/Scenes/Loader.unity";
private static readonly string MainScenePath = "Assets/Client/Scenes/Main.unity";
private ISceneManager _sceneManager;
void Start()
{
_sceneManager = new AdvancedSceneManager(true);
}
private void _OnConfigFileLoaded()
{
_sceneManager.SceneLoaded += _OnSceneLoaded;
_sceneManager.LoadAsync(MainScenePath, true);
}
private void _OnSceneLoaded(Scene scene)
{
_sceneManager.SceneUnloaded += _OnSceneUnloaded;
_sceneManager.UnloadAsync(LoaderScenePath);
}
private void _OnSceneUnloaded(Scene scene)
{
Debug.LogWarning($"Scene unloaded: {scene.name}");
} |
🤔 I'll take a look at it. |
I've figured it out! This only happens because the private static readonly string LoaderScenePath = "Assets/Client/Scenes/Loader.unity";
private static readonly string MainScenePath = "Assets/Client/Scenes/Main.unity";
private ISceneManager _sceneManager;
void Start()
{
_sceneManager = new AdvancedSceneManager(true);
}
private void _OnConfigFileLoaded()
{
_sceneManager.SceneLoaded += _OnSceneLoaded;
_sceneManager.LoadAsync(MainScenePath, true);
}
private void _OnSceneLoaded(Scene scene)
{
_sceneManager.SceneUnloaded += _OnSceneUnloaded;
_sceneManager.UnloadAsync(SceneManager.GetSceneByPath(LoaderScenePath));
}
private void _OnSceneUnloaded(Scene scene)
{
Debug.LogWarning($"Scene unloaded: {scene.name}");
} You could also just transition to the target scene, that will also unload the loader scene internally: private static readonly string MainScenePath = "Assets/Client/Scenes/Main.unity";
private ISceneManager _sceneManager;
void Start()
{
_sceneManager = new AdvancedSceneManager(true);
}
private void _OnConfigFileLoaded()
{
_sceneManager.TransitionAsync(MainScenePath);
} What are your thoughts on the package allowing cross-referencing |
This got me thinking: what would the Unity Scene Manager do? The answer: unload the last loaded scene that matches the reference. That being said, I'll update the code to allow unloading a scene by any matching reference. Your code should absolutely work. |
Just pushed the new version Now, you are able to unload any scene by using any of its valid references: Your original code should now work as expected. This is how I tested it: static readonly string LoaderScenePath = "Assets/Scenes/SceneA.unity";
static readonly string MainScenePath = "Assets/Scenes/SceneB.unity";
void Start()
{
AdvancedSceneManager.SceneLoaded += _OnSceneLoaded;
AdvancedSceneManager.LoadAsync(MainScenePath, true);
}
void _OnSceneLoaded(Scene scene)
{
AdvancedSceneManager.SceneUnloaded += _OnSceneUnloaded;
AdvancedSceneManager.UnloadAsync(LoaderScenePath);
}
void _OnSceneUnloaded(Scene scene)
{
Debug.LogWarning($"Scene unloaded: {scene.handle}");
} |
Hey João,
I'm trying 3.2-Pre.1 version.
A scene is not unloaded. Here is an example:
Here is a screenshot from the debugger to see that this scene is under the manager's control.
I hope this helps)
Thank you
The text was updated successfully, but these errors were encountered: