Search Unity

No UI Input Actions after Scene Load

Discussion in 'Input System' started by abob101, Oct 27, 2020.

  1. abob101

    abob101

    Joined:
    Oct 28, 2017
    Posts:
    26
    Hi all,

    I have 2 scenes both with some UI elements (buttons) and an Event System (set to use the new InputSystemUIInputModule) in each Scene. The Event System just looks like this, configured to use the DefaultInputActions asset:



    When I load either of these scenes standalone, everything works fine - the UI receives mouse clicks.

    When I load Scene A, and then load Scene B - there are no Actions loaded and the UI does not respond to mouse clicks. I can see in the Input Debugger that there are no Actions loaded/enabled as shown here:



    Whilst in play mode, if I then disable and re-enable the InputSystemUIInputModule component on the EventSystem (or just disable and reenable the entire EventSystem gameObject), then the UI starts working. I can see that after doing this all the Actions are loaded in the Input Debugger as shown here:



    So loading Scene A by itself works fine. Loading Scene B by itself works fine.

    Loading Scene A, UI works fine... then after loading Scene B no actions. Disabling and enabling whilst Scene B is playing and then it starts working.

    So it's like the Actions are not gettting enabled properly after the scene load...?? I am loading the Scenes by using SceneManager.LoadSceneAsync to load Scene B and then Unloading SceneA.... specifically Scene B is async load is started, wait for it to finish... then make Scene B active.... then unload Scene A.

    Is this a bug? Or something to do with the way i'm loading Scenes? There is an Event System in both Scene A and Scene B so i'm wondering if it is something to do with the fact that there would be two scenes loaded at the same time briefly before changing the active scene and unloading the other one.

    Any help much appreciated!
     
    fullerfusion, BAIZOR and jason-vreps like this.
  2. abob101

    abob101

    Joined:
    Oct 28, 2017
    Posts:
    26
    OK so I have managed to put a hack fix together for this by adding a new custom Component to the Event System object like this:

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.InputSystem.UI;
    4.  
    5. public class EventSystemEnabler : MonoBehaviour
    6. {
    7.     private InputSystemUIInputModule _inputSystemUIInputModule;
    8.  
    9.     void Start()
    10.     {
    11.         _inputSystemUIInputModule = GetComponentInParent<InputSystemUIInputModule>();
    12.     }
    13.  
    14.     private void OnEnable()
    15.     {
    16.         StartCoroutine(Co_ActivateInputComponent());
    17.     }
    18.  
    19.     private IEnumerator Co_ActivateInputComponent()
    20.     {
    21.         yield return new WaitForEndOfFrame();
    22.         _inputSystemUIInputModule.enabled = false;
    23.         yield return new WaitForSeconds(0.2f);
    24.         _inputSystemUIInputModule.enabled = true;
    25.     }
    26. }
    This "works"... but I don't understand why...... :confused:
     
    jason-vreps likes this.
  3. FergalM

    FergalM

    Joined:
    Sep 10, 2020
    Posts:
    1
    I had exactly the same problem, I guess it might be a bug.
    Also I noticed that changing the map actions made it works.
    I'll try to add it to Don'tDestroyOnLoad since I'm using the same settings !
     
  4. jason-vreps

    jason-vreps

    Joined:
    Sep 22, 2017
    Posts:
    16
    Same issue... any luck with a less hacky fix? :)
     
  5. Sebastiran

    Sebastiran

    Joined:
    Feb 23, 2017
    Posts:
    13
    Put the event system in a persistent managers scene.

    The problem might be in the way you load the scenes.
    Based on my experience:
    If you load the new scene before unloading the old one, it will ignore the event system of the new scene. Then, when unloading the old scene and with it the current event system, it will have no event system that it recognizes.

    I put my event system in the same scene as my audioManager (persistent managers scene) and removed it from all other scenes. That way I was able to solve to issue for my project.
     
    montr3uil likes this.
  6. BAIZOR

    BAIZOR

    Joined:
    Jul 4, 2013
    Posts:
    112
    EDIT: nevermind, I just loaded the scene with the parameter - Physics2D, looks like it just ignores physics in the scene. Didn't know about that.

    I found another problem. Nothing can fix it except to have a single scene.
    • tried script from @abob101
    • tried to make a persistent (DontDestroyOnLoad) Camera+PhysicsCollider2D with EvenSystem+InputSystemUIInputModule.
    Just need to have a Collider2D such as BoxCollider2D and try to handle any event from it. Such as Drag, and even use the default Button component. The BoxCollider2D never receives events.

    That may work only if I have a single scene.
     
    Last edited: Oct 16, 2021
  7. llentinantl

    llentinantl

    Joined:
    Jun 7, 2017
    Posts:
    17
    In my experience, some issues with input can happen when you load scene with Player Input component as additive. However, this only reproduces for me in editor - when I build and run, Player Input in loaded scene works just fine.
     
  8. bartofzo

    bartofzo

    Joined:
    Mar 16, 2017
    Posts:
    151
    Having the same issue on 2020.3.16f1. Disabling and re-enabling the module works. But not when I call
    TouchSimulation.Enable() somewhere...
     
  9. unitj75

    unitj75

    Joined:
    May 30, 2022
    Posts:
    26
    I'm having this issue as well. Is disable/enable the fix that's working for folks?
     
  10. OlehHalytskyi

    OlehHalytskyi

    Unity Technologies

    Joined:
    May 16, 2022
    Posts:
    2
    Hi!
    Did anybody submit a bug report with the reproduction project to Unity?
     
  11. scottygavin

    scottygavin

    Joined:
    Feb 25, 2021
    Posts:
    10
    Heya!

    Eventually I only needed to Destroy() my mono singletons during Unload/LoadScene(..).
    UI events are working without performing eventSystem.SetActive(false/true);

    e.g.

    SceneManager.LoadScene("Blank");

    SceneManager.UnloadScene("Global");

    //Destroy normal C# Singleton objects
    BiomeEngine.Instance.RecreateSingleton(); //Instance = null

    //Destroy Monos so that all their fields/props are reinitilized
    Destroy(ExplorerManager.Instance);

    SceneManager.LoadScene("Global");

    ....

    There is probably a pattern concerning this..??
     
  12. Alligator_2014

    Alligator_2014

    Joined:
    Jan 5, 2024
    Posts:
    1
    I have event system in my scenes, at the start buttons work as usual, but when I load another scene and then load the first scene the buttons do not work. I tried the options that some suggested, but nothing works:(