Unity 5.3 is a 2D game. On the stage there are two canvas: one to display the menu, the second to display the interface of the scene. The interface's original canvas is hidden. When you click on the New button, a new game starts, and when you click on Load, a load from save occurs. In both cases, the canvas menu is hidden, and the interface becomes active via SetActive(true); Further, buttons from the interface that depend on the loaded location are created from the prefab. The buttons are bound to the canvas of the interface via btn.transform.SetParent(canvas.transform);

When you start the game, the created buttons appear in the hierarchy and are tied to the canvas, but they are not visible on the scene. If you then exit the menu and load from save or start a new game, the same buttons appear on the scene. What could be the reason for this flicker? And how to make the buttons appear immediately?

  • I solved the problem by changing the hierarchy on the stage. Left one canvas and buttons earned normally. - Alex
  • If possible, publish the solution found in response to your question . I am sure it will help many of your colleagues in the future. - Nicolas Chabanovsky

1 answer 1

In my practice, the best solution is to use UI elements on canvas. If possible, the canvas scaler should be any area around "match width and height". Otherwise, the text and the textures themselves will be blurred. Especially the text. And do not use outdated GUI. (this is me just in case)

Create a canvas, then stupidly place the buttons at your convenience. When you need to hide the menu - just turn off the canvas and all children will be disconnected in one group.

I would not advise to generate such buttons as "new game start" and "load". Just because it is so difficult to make them quite beautiful and to attach animations to them is a little more difficult. It's like the very least :)

You can also disable the panel (child element of the canvas) on which objects will be placed (in this case, the button). Alternatively, disable the renderer.

I make a lot of panels inside the canvas and switch between them.