Reputation: 387
I just updated from Unity 2019.3.13f1 to 2021.3.6f1 mid project. Not ideal I know, but I was advised to by Unity Support in order to add the IAP package. After the update, on running my launch scene, I get this error:
There are 2 event systems in the scene. Please ensure there is always exactly one event system in the scene
It turns out, a second EventSystem object is being created on running, which hadn't been the case before the update. At first, I just disabled the one in the hierarchy, which solved the problem as the second EventSystem then didn't conflict. However, when the game goes to a second scene and then returns to the initial scene, the duplicate EventSystem is not created, meaning that the menus don't get any input!
Can anyone advise?
Upvotes: 2
Views: 1301
Reputation: 387
This forum post (https://forum.unity.com/threads/upgrade-to-2020-lts-creating-duplicate-eventsystem.1098133/) detailed the same problem.
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.
The poster there solved it by surrounding the Initialising line with #if !UNITY_EDITOR. However I wanted to be able to see the adverts testing in the editor - so I added this code, after Advertisement.Initialize(_gameId, _testMode, this):
var es = FindObjectsOfType<EventSystem>();
if (es.Length > 1)
{
for (int i = 1; i < es.Length; i++)
{
Destroy(es[i].gameObject);
}
}
This seems to have fixed the problem.
Upvotes: 1