Search code examples
unity-game-engineunity3d-gui

Same GUI multiple scenes in Unity game - prefab of Canvas?


My problem is how to share same GUI in multiple scenes.

For example:

I have Inventory GUI on Farm scene and I need this GUI on other scenes like Castle, Dungeon etc.

It's good idea to make prefab of Canvas? Or design again the GUI? What about mixing "shared GUI" and individual GUI like Dialogs etc.?

Thanks for any answer.


Solution

  • You can certainly make a prefab of a canvas for each screen you need although if you have to destroy it and respawn it a lot it could cause a performance hit. An alternative is to create a single canvas with all the screens as children, all disabled, and enable each as necessary. This has the advantage of not doing lots of computation at once but on the downside there's some overhead for keeping it all in memory. For a small game I would recommend the latter and if you need to scale it up you can mix the two: have canvases with more than one related screen, ideally screens grouped in such a way that they are only accessible in certain situations, letting you keep as few canvases in the scene as possible.