Have method HideButtonMenu() which hides menu(loading scene minigame), but method Load() runs before LoadScene.
public void HideButtonMenu()
{
SceneManager.LoadScene("minigame");
PlayerController.Load();
}
How to load scene fully before loading?
Hi @vtchom3 !
I would recommend utilizing the SceneManager’s sceneLoaded delegate. This delegate is called whenever the SceneManager is done loading a scene.
This would look something like this:
public void HideButtonMenu()
{
//Add delegate to SceneManager.sceneLoaded. This is called when the scenemanager has loaded a scene.
SceneManager.sceneLoaded += LoadPlayerController;
//Load specified scene.
SceneManager.LoadScene("minigame");
}
private void LoadPlayerController(Scene scene, LoadSceneMode mode)
{
//Load your playercontroller
PlayerController.Load();
//In case you don't want your playerController to be loaded every time a scene is loaded (Not just your minigame scene) it's a good idea to remove the "LoadPlayerController" void from the delegate.
SceneManager.sceneLoaded -= LoadPlayerController;
}
Because you’re adding a void to the sceneLoaded event the overloaded values scene and mode are both returned. You don’t need to use them but could use them to confirm which scene has been loaded and execute scene specific code with that. (such as loading different player controllers for different scenes)
Even though you might not need them or even want them you’ll have to keep them as overloaded values. If you add a void without these values you’ll get an error because the delegate is expecting them.
Another way of doing this would be to load the playercontroller in the scene you’re loading. That would also make sure your scene is done loading before loading the player.
I hope this helps!
Wybren van den Akker
Unity Support