Trying to understand the Unity UI system.
I have a panel that contains a button that should hide the panel.
When I wire the button up to the method that hides the panel, I can see in the console that the method is called but it has no effect.
However if I call an intermediate method from the button that uses the monobehavior Invoke method to call the disable method, even with a delay of 0, it does work.
Does not work:
public void DisableUI(string sentBy)
{
print("disabling UI from: " + sentBy);
_panel1.gameObject.SetActive(false);
_secretPanel.gameObject.SetActive(true);
_uiActive = false;
}
Does work:
public void DisableUI(string sentBy)
{
print("disabling UI from: " + sentBy);
Invoke(nameof(SetUiInactive), 0f);
}
private void SetUiInactive()
{
_panel1.gameObject.SetActive(false);
_secretPanel.gameObject.SetActive(true);
_uiActive = false;
}
Note that calling the function directly from another script does work as expected.
Can anyone explain what's going on?
Thanks for any help.