Search Unity

Ui delegate text button not working after scene change

Discussion in 'Editor & General Support' started by Unplug, Sep 20, 2020.

  1. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    Hello, i know there are a ton of question about this, but i've read a lot of them and haven't been able to find the solution yet.

    1-When i load the game, the splash screen and mainmenu is loaded in a "dontdestroyonload" scene and all scene are loaded async.
    2- After splash screen you reach start up menu, and it work. I can click it and all action work.
    3- when starting a level, the pannel is deactivated untill you push escpace to activate it back. The click behavior doesn't work anymore

    A- Yes, the eventsystem is still in the scene, it is also reporting the click on the right object
    B- The button react to mouse over and click (color change and sound are working)
    C- no image/sprite or other UI element block reaction to the panel
    D- yes everything have "interactable" checked

    action are added this way in the Awake
    Code (CSharp):
    1.                 Options.onClick.AddListener(delegate { OnOptionsButtonClick(); });
    2.  
    some have suggest to put the code in "start" but the object is in the same scene and shall not be a problem of gameobject not existing yet (if that was the case, it wouldn't work in the first scene anyway).

    During scene load, the pannel is move to a different location (the menu stand to the right in splash screen and is center while in the game). can this be a problem ?

    is it because the application "loose focus" ? when i push escape i unlock the cursor so that you can move your mouse around and click the menu, which also make you loose focus on the application

    any black magic to check ?
     
  2. Unplug

    Unplug

    Joined:
    Aug 23, 2014
    Posts:
    256
    I'll share the solution if anyone get the same problem.

    I had a "lateupdate" that was changing cursor lock mode to "locked" when you press the mouse button. This force the mouse to go back to center, so despite that fact that the button was clicking and working, the cursor was probably moving too soon make it outside of the button and also out of the "drag" limit for the button. I have added the lock state change at the end of the onclick function and now it work as normal... such a pain