Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How does everyone go about prefabbing their UIs?

Discussion in 'UGUI & TextMesh Pro' started by Iron-Warrior, Dec 10, 2015.

  1. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    836
    Hey,

    I'm getting to the point in my project where I'm almost ready to start building multiple levels, which means I need some way of moving the UI around to each individual level. However, unlike a player character or weapon or whatever, you can't really do this with the UI. If your UI has any kind of features that are repeated and are prefabs themselves, they will be overwritten when you prefab the entire thing.

    The only solution I can think of is using LoadLevelAdditive and storing my UI within a scene that gets loaded before any level is...and I think this would work pretty well, but it seems like it should be a pretty universal problem so I was interested in what everyone else's solutions were.

    Erik
     
  2. michaelhill

    michaelhill

    Joined:
    Nov 4, 2015
    Posts:
    10
    You might want to look in to DontDestroyOnLoad. You can apply it to a specific object so that when the next scene loads, that particular object will carry over.
     
  3. comixplay

    comixplay

    Joined:
    Sep 27, 2013
    Posts:
    104
    I don't understand the problem - what is the difference between instantiating the player character in each level and instantiating a UI object?
     
  4. Iron-Warrior

    Iron-Warrior

    Joined:
    Nov 3, 2009
    Posts:
    836
    That would also work too, as long as you load the UI in a main menu scene and just disable it until you've entered a gameplay scene.

    If your UI uses any kind of prefabbed elements, like buttons that are repeated, when you store the entire UI as a prefab the nested prefabs will be overwritten and no longer maintain their prefab link.