Search Unity

Cannot Get World Space Object to Display in Front of GUI Menu

Discussion in 'Scripting' started by clamum, Aug 15, 2020.

  1. clamum

    clamum

    Joined:
    May 14, 2017
    Posts:
    61
    I had this working before, but had to change things around because my Canvas size was all wrong, then I couldn't get it working again.

    Then I switched my Canvas's Render Mode to "Screen Space - Camera" and got this working with that, but it was kinda weird to work with and then I couldn't get some UI element (a loading bar) to display.

    So I'm back to trying the Canvas "Screen Space - Overlay" render mode.

    What I have is the main menu for my game, in your typical Canvas with various UI elements like buttons and images.

    I want to have an object flying around in front of that, in a circle. I have the object's flight working; it flies in a circle.

    I have the Main Camera so it's basically looking up at the object I have flying. Now when this was working, this object would be flying around in front of the UI menu.

    But it's not working now. If I look at the camera preview window (see pic below) the object is right there, but when I start the game just the main menu is displayed, with no object.

    It's probably something dumb but I'm a Unity noob and just can't figure this out. See pics below for various settings. Any help would be greatly appreciated! Thank you.

    Pic of main menu with the Main Camera selected and showing that it sees my flying object:
    Annotation 2020-08-14 224256.png

    Pic of Main Camera settings:
    Annotation 2020-08-14 224202.png

    Pic of Canvas settings:
    Annotation 2020-08-14 224329.png
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    This can come from trying to mix SpriteRenderers with UI components. Sprites are not UI components. If you want to mix graphics with UI Components such as text, best to use a UI.Image component.

    NOTE: both SpriteRenderer and UI.Image will accept a sprite graphic, so that can be a source of confusion. If you just drag a Sprite into the scene, Unity does not (at least last time I checked) make a UI.Image, but rather a SpriteRenderer. You need to make an Image, then add the Sprite to that.

    You can see if you have SpriteRenderers in the scene by putting t:SpriteRenderer in the scene or hierarchy search field at the top.

    If that's not it, then run the game, then hit pause and go digging through the UI hierarchy turning stuff off until the buttons appear the way you want, and then you can kinda understand what was blocking them before, and perhaps reason about why they were blocking them.

    Also, this can arise from mis-specifying a sorting layer or sorting order on one or more items.
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,689
    Finally if you DO want to mix and match SpriteRenderers and UI components, google up specifically about doing that. There's a whole bunch of things to take into consideration, which is why I tend to never do that if possible. Sticking with UI items ensure they "play well together."
     
  4. clamum

    clamum

    Joined:
    May 14, 2017
    Posts:
    61
    Thank you for the reply, I appreciate it.

    It doesn't look like I have any SpriteRenderers in my game (I did the "t:SpriteRenderer" search in hierarchy). Doesn't surprise me because I actually am not familiar with them and don't think I've used them before.

    *Removed unrelated problem to my original question*
     
    Last edited: Aug 18, 2020
  5. clamum

    clamum

    Joined:
    May 14, 2017
    Posts:
    61
    WOOT. Sorry, my last reply was talking about a loading indicator when my original question was the bird not flying in front of the GUI even though it looks fine from the Main Camera point-of-view.

    I remembered reading recently that putting all your stuff in the same Canvas can cause problems.

    But I put the loading indicator stuff into their own Canvas with higher Sort Order and that fixed that problem.

    Now just need to figure out that stupid bird flying in front of GUI problem still. :(

    Untitled.png
     
  6. clamum

    clamum

    Joined:
    May 14, 2017
    Posts:
    61
    Well I just went back to "Screen Space - Camera" for the GUI (main menu) Canvas's "Render Mode."

    Since adding a new Canvas specifically for the loading indicator and seeing that work, I figured if I went back to that SS-C render mode that everything would work, and sure enough it did.

    DO NOT put all your GUI stuff into the same Canvas. You definitely can get drawing issues like I have had.

    Now I just need to adjust my flying object so it goes behind the menu and in front of it (it just stays in front now) but I should be able to do that. WOOT. Thanks for your replies Kurt!

    Flying in front of menu:
    Annotation 2020-08-20 213920.png

    Here he's still in front of menu but at this part of the circle he's flying I want him behind it:
    Annotation 2020-08-20 213957.png