Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Upgrade to 2020 LTS creating duplicate EventSystem ?

Discussion in 'UGUI & TextMesh Pro' started by LesBloom, Apr 23, 2021.

  1. LesBloom

    LesBloom

    Joined:
    Feb 2, 2017
    Posts:
    163
    Hi all,

    My project was working fine with the 2019 LTS. I just upgraded to the 2020 LTS, and am now having this issue.

    My starting scene has an EventSystem already in it. Pretty sure it's just default values. This is what it looks like.
    upload_2021-4-23_8-12-31.png

    However, as soon as I hit play. Another EventSystem is automatically created and added into this scene. This EventSystem has an additional component (BaseInput) on it. Having 2 EventSystems then causes a series of errors. This is what the additional EventSystem looks like.
    upload_2021-4-23_8-15-28.png

    This only happens when I play in the Editor. It does not repro in standalone Android builds.

    I have scoured my own code, and I do not see anything that would be creating a new EventSystem.

    I tried deleting my EventSystem, however then standalone Android builds fail (because there is no EventSystem and this bug only happens in Editor).

    I have tried adding the BaseInput component to my EventSystem. No change.

    I have tried deleting my EventSystem and building a new one. No change.


    Any information would be greatly appreciated.
    Thank you
     
  2. LesBloom

    LesBloom

    Joined:
    Feb 2, 2017
    Posts:
    163
    I have tracked this down to calling Advertisement.Initialize.

    If I call that while running in the Editor; then it creates a new EventSystem.

    I am not sure why. It doesn't seem to matter if I pass true or false for the testMode value.
     
  3. Racso_JC

    Racso_JC

    Joined:
    May 18, 2019
    Posts:
    3
    Has anyone found a solution for this issue? It's exactly as LesBloom says.
     
  4. LesBloom

    LesBloom

    Joined:
    Feb 2, 2017
    Posts:
    163
    @Racso_JC , I never did find a proper solution for this. I ended up needing to wrap my Advertisement.Initialize code with #if !UNITY_EDITOR =/
     
  5. quoxel

    quoxel

    Joined:
    Nov 28, 2008
    Posts:
    65
    I just had the exact same problem after updating to 2021 LTS, so I'm very happy to have found this thread!

    In my case, I wanted to be able to test ads in the editor, so I added the following code after Advertisement.Initialize(_gameId, _testMode, this) and it seems to do the trick.

    Code (CSharp):
    1. var es = FindObjectsOfType<EventSystem>();
    2. if (es.Length > 1)
    3. {
    4.     for (int i = 1; i < es.Length; i++)
    5.     {
    6.         Destroy(es[i].gameObject);
    7.     }
    8. }
     
    LesBloom likes this.