Forum rules - please read before posting.

Unity UI Problem & Good usage

edited January 2016 in Technical Q&A
Hi everyone.

I'm starting to get problems when using Unity UI as our project scales up. I guess I'm using it the wrong way, so if you have a better solution I'd be glad to know.

I'm trying to make a Splash screen. It's always the same background and 2 changing texts : the title & a subtitle.

We have it displayed 3 times on 2 scenes :
- Scene 1 : [1st splash] ** do something ** [2nd splash]
- Scene 2 : [3rd splash]

I created one prefab for the 3 splashs, so they share the same ID.

I've tested 2 solutions, each one fails short on a different point :

1°/ After creating the prefab, I created 3 menus in the Menu/Editor with differents texts. Source is set to -> Unity UI Prefab.
It works well, but the problem with this solution is that it instantiates every splash screen in every scene (splash 1, 2 and 3 in both scenes). It means that if the game has 50 splash screens (one or 2 for each level), I'll always have 49 useless duplicates in memory. Sounds bad...

2°/ After creating the prefab, I instantiated it in each of the 2 scenes. Then, I created 3 menus in the Menu/Editor with differents texts. Source is set to -> Unity UI in Scene.
In that case, only the very first menu of scene 1 works. It's due to ID confusions.

So, that's my problem, I don't know what to do to get only ONE instance of the splash screen in my scene and get it to work by turning on Menus. Anyone has a better solution ?


  • 1) This method shouldn't see your UIs duplicating whenever you change scene - there should only be three across all scenes.  If you've duplicated your Canvases, check that the ConstantID numbers on them are all unique (just find the Constant ID component on them).  Also make sure that Retain in prefab is checked.

    2) Same here - all ID numbers need to be unique, otherwise AC won't be able to tell them apart.  If you find a duplicate ID, then reset the Constant ID component to generate a new one.  AC will automatically prevent duplicates when working with objects in the same scene - so if you ever want to duplicate a UI, do so in the scene and make a new prefab from it - rather than duplicating the prefab file itself.
  • edited January 2016
    Let's take another example of the same problem. I have an instructor. It's just popping with a speech bubble and it says a sentence.

    1) Yes, sorry for not being clear, it's the case, it's not creating additional splashs. It's just that, for my instructor, I have a hundred occurences in the game. It means my UI view has all the instructor's appearance instanciated in every scene.
    I have 20 different scenes and in each one, the instructor is called 5 times. I shouldn't have 100 instructors (with only 5 to appear in this scene) in my UI view, it can't be the right solution.

    2) I should create one different splash prefab for each occurence of the menu? I mean, only the text changes. It means creating 100 different prefabs only to generate different IDs. It sounds wrong.

    What surprises me is that it was working before I updated (I was in AC 1.42). So I don't know if it's a bug or a feature :)

    When I only had one instance with the right ID in the scene, it used to work.
    I had dozens of different menus (as defined in the menu editor) pointing at the same instructor and it displayed correctly.
    I used the same prefab in all different scenes. I only instanciated it once per scene it needed to be and it used to work.

  • 1) I'm afraid I'm still not clear - you say it's not creating additional UIs, yet you have all instantiated in your scene.  Could you provide screenshots to explain?

    2) I wasn't suggesting that - just trying to help with the problem related to 3, not 100.  Have you thought about using tokens?  That way, you can just have one UI and change the label text dynamically:

    Create a Global Variable of type "Pop Up", and enter in each of the texts that the splash screen can have.  You can then display that Variable in your Label (see this tutorial), and change it's value (using the Variable: Set Action) to change the UI text.
  • I tried with the tokens, but the drawback is that texts don't appear in the "Game texts", so getting texts to be translated can be a real pain.
    Unless you have a solution to get variables in the Game texts?

    (BTW, I don't know if you saw I edited the second part of my previous answer)
    I'm making you a screenshot.
  • 1°/ Unity UI Prefab solution

    Here is what is instanciated in every scene.

    Here is the description in the "Menu" menu :
  • edited January 2016
    I see.  You shouldn't have two Menus share the same UI canvas - that'll cause problems.

    One other option is to use one Menu/UI, but three separate Labels inside it that get shown/hidden as appropriate.  Best to temporarily switch back to Adventure Creator as the Menu's source while you set up the logic, and then switch back to Unity UI once it's set up correctly.  You can use the Menu: Change state Action to show/hide individiual elements, or use Object: Animate if you prefer to control the visibility with animation clips.
  • Ok.
    My problem is that my project already has 10 splash screens and dozens of instructors all around, with the shared canvas through all scenes. It used to work so I built upon it. It's just no longer working.
    The example I'm giving is just a sample code to isolate the root cause of my troubles.

    That's why I'm really looking into a fully operational solution, because I'll have to rearchitect all my UI. I see there is no straighforward solution for my problem :)

    If you had to make an instructor for a new AC project (100 instructor appearances through 10 scenes), how would you proceed? - Something like the (in)famous Clippy ! :)

  • Personally, I'd do it all through narration speech: if you create a Dialogue: Play speech Action that has no character assigned as the speaker, it'll be considered a narration.  I'd then create a new Subtitles menu that's limited to display only narration speech, and style it to look like the graphic above.

    That said, the ability to translate String and PopUp variables would be a useful feature - I'll look into it in a future update.
  • Thanks a lot for your insight and your time.
    AC is my prefered Unity Asset, and you really manage to do something impressive with it...
    I hope your consumer base grow, you desserve it!
    Keep up the good work!
  • Just to note, I have done this effect with a few sprites, fading in and out, with engine:pause inbetween. Was easiest solution.
  • I'm having a similar issue, I've got over 40 menus which I set up in AC but I'm now switching to Unity UI because I need the menus to work in worldspace for VR reasons, it works for one menu when I use Unity UI in Scene, but apparently I can't use the same Canvas for multiple menus. It's not reasonable to try to create over 40 Unity UI's in scene or prefabs. It would have made sense if one UI in scene could be populated dynamically by AC as each menu is activated and the content should be wiped dynamically as the menu is deactivated. Has anyone found a way to do this?
  • You can hook into the OnMenuTurnOn custom event to control the contents of a Menu as it turns on - see the Manual's "Menu scripting" chapter.
  • Thanks Chris, I've had a look at this, but the problem is kind of different. I've created a new post as the thrust of the matter seems to be a bit different from the original post here. 

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.