Search Unity

UI vars disappearing after the canvas are re-initialized

Discussion in 'UGUI & TextMesh Pro' started by arturmandas, Aug 22, 2014.

  1. arturmandas

    arturmandas

    Joined:
    Sep 29, 2012
    Posts:
    240
    Welcome,
    I built UI system consisting of several canvas, which I instantiate from Resources folder for every screen of my game, and each of these screens is a separate state of my custom state machine (I instantiate those canvas in my OnActivate() method). All my buttons have their methods assigned from script. Now, it all looks like this:

    void InitUI()
    {
    canvasAboutMenu = (GameObject) Instantiate (Resources.Load("CanvasAboutMenu"));
    canvasAboutMenu.SetActive(true);

    var buttonBack = GameObject.Find("Button_Back").GetComponent<Button>();
    buttonBack.onClick.AddListener(Back);
    }

    I then switch between canvas using .SetActive(), where needed.

    Everything seems to works fine, but just once. I mean, when I visit each screen more than once, clicking on buttons have no effect - as if those variables were somehow lost. Am I doing something wrong?
     
  2. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    that seems like it should be working. Can you log a bug for us to look at?
     
  3. arturmandas

    arturmandas

    Joined:
    Sep 29, 2012
    Posts:
    240
    sure, please let me know how to do it.
     
  4. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    Help -> Report a Bug
     
  5. arturmandas

    arturmandas

    Joined:
    Sep 29, 2012
    Posts:
    240
    thank you!