0

I come from an iOS/OS X background and now use Unity3D a lot.

I would like to know if there is a way to create a UI in a separate scene in Unity and include that UI in multiple other scenes? Much like loading the same view from a xib in Xcode.

Rob Sanders
  • 5,197
  • 3
  • 31
  • 58
  • 3
    How about just making your UI GameObject [a prefab](http://docs.unity3d.com/Manual/Prefabs.html)? Then you can `Instantiate()` it in any scene you like, whenever you want. – Serlite Apr 19 '16 at 14:47
  • Or you could as well create the UI object in the very first scene and call **DontDestroyOnLoad()** on them so that they are carried around from scene to scene. Then just call **SetActive(true/false)** on them. I have an **Instantiate()**-o-phobia because it causes fps hiccups sometimes. – Nika Kasradze Apr 19 '16 at 14:53
  • Thanks for the ideas. I've gone with `SceneManager.LoadScene(1, LoadSceneMethod.Additive);` – Rob Sanders Apr 19 '16 at 15:28
  • Hi RASS. basically that's wrong :) don't do that. it won't work. quite simply, you will need a preload scene anyway. put your Canvas and the code for the canvas on the preload scene. Add 1 line of code "DontDestroyOnLoad". you're done. – Fattie Apr 19 '16 at 15:32
  • here's some dope on it http://stackoverflow.com/a/35891919/294884 – Fattie Apr 19 '16 at 15:32

1 Answers1

0

Turns out there are quite a few ways to do this (see comments on question).

  • Prefabs

  • DontDestroyOnLoad

  • SceneManager additive loading (my choice).

Rob Sanders
  • 5,197
  • 3
  • 31
  • 58
  • it's an absolute basic of unity that you just have the UI in the preload scene, and it's DDOL. in unusual cases, sure, you could use a prefab and load it again. note too that, there would be absolutely nothing wrong with simply ................. having the same UI in the different scenes! (After all, everything else - Mario, the sky, etc - appears "in different scenes"). Using scenemanager-additive is pointless and will tie you in knots (think about when you want t move to other scenes!) – Fattie Apr 19 '16 at 15:34
  • Surely if you just have a script in each scene that wants the UI that calls the additive load method it will work? Seems to be appearing in my test project. I've played around with `DontDestroyOnLoad` before and didn't get on with it. – Rob Sanders Apr 19 '16 at 15:39
  • you mean you're additiving the UI? – Fattie Apr 19 '16 at 15:44
  • you wont be able to not get on with DDOL :) unity's weird, you have to go with it. I guess, you had scenes A,B,C and say A had something DDOL. then, you were going back and fore between A,B,C and it was getting mixed up, too many copies of stuff etc? it's just how it is, you have to have a preload scene (only ever visited once - when your splash screen is up basically) with "whole game" stuff in there (marked DDOL). it's just unity! – Fattie Apr 19 '16 at 15:46