Search Unity

Question Using only one EventSystem

Discussion in 'Editor & General Support' started by afurioso, Aug 31, 2022.

  1. afurioso

    afurioso

    Joined:
    Jan 12, 2022
    Posts:
    88
    Hi, I have a problem with multiple scenes.

    I'm in the first scene and when I clicked a button to change the scene (it loads the scene in async mode), I got this message:

    Code (CSharp):
    1. There are 2 event systems in the scene. Please ensure there is always exactly one event system in the scene
    2.  
    Now, in the second scene, I know that I have another EventSystem but I want to avoid getting this error every time. So how can I use only one EventSystem (those from the 1st scene)?
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    Don't have an EventSystem in the 2nd scene. Or maybe have 1 event system and add it to DontDestroyOnLoad?
     
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,927
    This, or have it in an ever-present additively loaded scene.
     
    DevDunk likes this.
  4. afurioso

    afurioso

    Joined:
    Jan 12, 2022
    Posts:
    88
    I need it in the second scene. I also tried with DontDestroyOnLoad but it doesn't work. It seems like is inactive
     
  5. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    What about the additive scene method?
    Then you will only have 1
     
  6. afurioso

    afurioso

    Joined:
    Jan 12, 2022
    Posts:
    88
    I'm pretty new. Can you explain it to me?

    I have a button in the first scene and when I clicked it, the app changes the scene. I set there my DontDestroyOnLoad
     
  7. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    If you fully want to change the scene why do you load them additively?
    If you just switch a scene it will only use the event system from that scene. If you load scenes additively it can give issues like this
     
  8. afurioso

    afurioso

    Joined:
    Jan 12, 2022
    Posts:
    88
    I need it in the second scene because there is another canvas in there.

    The first scene is a menu with a button and the second scene show a gameobject and other things but has a button to come back to the first scene and other buttons that activate other functions
     
  9. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,060
    Then just like you load the second scene, load a third scene with just an event manager (do this at Awake in the first scene). And remove the other event systems
     
  10. afurioso

    afurioso

    Joined:
    Jan 12, 2022
    Posts:
    88
    I don't understand. Why should I load and create a third scene only with an eventsystem?
     
  11. afurioso

    afurioso

    Joined:
    Jan 12, 2022
    Posts:
    88
    For future people.

    I SOLVED. I made the script below and I attached it to an empty game object in the second scene. In this way when I try to load the second scene, asynchrony during unity unload the first scene, after one second it instantiates the event system.

    Code (CSharp):
    1. public class EventSystemManager : MonoBehaviour
    2. {
    3.     public GameObject eventSystem;
    4.  
    5.     void Start()
    6.     {
    7.         StartCoroutine(Coroutine());
    8.     }
    9.  
    10.     IEnumerator Coroutine()
    11.     {
    12.         yield return new WaitForSeconds(1);
    13.         Instantiate(eventSystem);
    14.     }
    15. }
     
  12. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,927
    Many projects need to have something or some things that are/is 'always present' in the background and live between levels/scene loads. You can use DontDestroyOnLoad for this, but an additively loaded scene is something you have more control over.

    Most projects only need one event system, so it usually gets thrown into this scene.