- Home /
Problem solved.
UI doesn't render after scene reload.
So this is a legitimate concern. I have 2 seperate scripts in my game: 1 for a pause menu, and 1 that manages the whole main menu and level select screen. So the main menu works perfectly and all. I should note that the main menu and level select screen are two separate canvasses and that switching between the menu screen and the level select screen just sets one of the two canvasses active or inactive. Now, when I go into my actual game and wanna quit back to the main menu via the pause menu, none of the UI elements show up after I reload my scene. But when I look into the hierarchy while in play mode both canvasses show up active. After I turn off play mode, both canvasses reappear. Anyone know what's going on here? I should also probably note that on setting active of the main menu canvas I have some animations that play (that fades in the text and buttons and so on). I tried exporting the game to see if this was an editor-only issue but this was not the case. These are my scripts:
Main Menu:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class menuScript : MonoBehaviour {
private GameObject mainMenu;
private GameObject levelSelectScreen;
void Start () {
mainMenu = GameObject.Find("MainMenu");
levelSelectScreen = GameObject.Find("LevelSelect");
mainMenu.SetActive(true);
levelSelectScreen.SetActive(false);
}
public void startGame () {
SceneManager.LoadScene("stages");
}
public void QuitGame () {
Application.Quit ();
}
public void levelSelect () {
mainMenu.SetActive(false);
levelSelectScreen.SetActive(true);
}
public void goBack () {
mainMenu.SetActive(true);
levelSelectScreen.SetActive(false);
}
public void world1 () {
mainMenu.SetActive(true);
SceneManager.LoadScene("stages");
}
public void world2 () {
mainMenu.SetActive(true);
SceneManager.LoadScene("stages2");
}
}
All these public voids are being called by UI buttons through OnClick.
Pause Menu Script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class pause : MonoBehaviour {
private GameObject pauseMenu;
void Start () {
pauseMenu = GameObject.Find("PauseMenu");
}
public void resumeGame () {
GameObject.Find("Player").GetComponent<player>().gamePaused = false;
Time.timeScale = 1.0f;
pauseMenu.SetActive(false);
}
public void quitGame () {
Application.Quit ();
}
public void backToTitle () {
SceneManager.LoadScene("title");
}
}
Again these are being called by UI buttons.
Does anyone know what's going on here? Am I doing something wrong? I don't get any compiling errors or exceptions. And I can't seem to find the problem. Does it have anything to do with setting canvasses active or inactive? Or the fact that there are two canvasses? Please let me know. I am using Unity 5.6.4p2