- Home /
Difficulty with pausing and resuming EventSystem
I am making a pause screen for my game. Since there are multiple playable scene's I thought of having a pause scene and load it additive then and unload it, instead of prefabbing a canvas and instantiating every time.
Now some scene's have already have an Event System, so I disabled previous scene event system and enable when Pause scene unloads.
But the problem is that when I disable the event system script, the current input module gets set to none and remains that way even after being enabled.
Here's is part of Level Manger script responsible for loading Pause Scene (unload is handled from Pause Scene itself)
private void Start()
{
if (FindObjectOfType<EventSystem>() != null){
eventExists = true;
es = FindObjectOfType<EventSystem>();
}
}
private void Update(){
if (Input.GetKeyDown(KeyCode.Escape) && !onPause) {
if (eventExists){
es.enabled = false;
}
SceneManager.LoadSceneAsync![alt text][1]("Pause", LoadSceneMode.Additive);
StartCoroutine(SetActive(SceneManager.GetSceneByName("Pause")));
Time.timeScale = 0;
onPause = !onPause; //onPause is a public static bool
}
if (!onPause && Time.timeScale == 0){
if (eventExists) {
es.enabled = true;
Debug.Log("enabling event system");
}
Time.timeScale = 1;
}
}
public IEnumerator SetActive(Scene scene){
int i = 0;
while (i == 0){
i++;
yield return null;
}
SceneManager.SetActiveScene(scene);
yield break;
}
[1]: /storage/temp/104209-input-unity.png
Answer by RetroGeek46 · Oct 23, 2017 at 06:01 PM
Turns out I only had to call UpdateModules()
on the event system object es after enabling the EventSystem once again at line 21. Also, this should be done when scene has completely finished unloading (which happens asynchronously) so just check for active scene to not be Pause before enabling it (add a condition in if statement SceneManager.GetActiveScene().name != "Pause"
)
Your answer
Follow this Question
Related Questions
EventSystem events reaching parent EventTrigger? 0 Answers
Hook up external Events into Unity Events System 0 Answers
How to evoke OnMouse Events with VR controller 0 Answers
StandaloneInputModule allowActivationOnMobileDevice vs forceModuleActive 0 Answers
How do I add a value to anywhere Input.GetAxis("Horizontal") is called? 1 Answer