Search Unity

Sprite over Overlay Canvas - Render Order Challenge

Discussion in 'Universal Render Pipeline' started by Kazko, Nov 28, 2019.

  1. Kazko

    Kazko

    Joined:
    Apr 2, 2014
    Posts:
    82
    TLDR version: is it in any way possible to render sprite on top of overlay canvas? Using one camera in URP.

    Sprite on top of overlay sounds weird, but consider my case in the full post, and perhaps suggest another way of solving this.

    ---
    I can't figure this out. Consider the following situation: I want to create a load transition based on a tilemap grid, that is partially transparent and reveals a bit of the scenes that are being additive loaded "below". Part of the scene below is a user interface in Overlay canvas that is being loaded as well. This is in URP project.

    All is good until we mix in the UI Overlay Canvas, that should be partially hidden by the transition like the rest of the objects. The reason is that I can't use overlay canvas for the transition itself, because tilemaps dont work with canvas very well. Therefore, the transition has to be in worldspace, at which point the overlay canvas of the UI elements below will be drawn on top of the transition. The only way to solve this is using Worldspace canvas for the UI and a sorting order.

    Using worldspace canvas seems wrong, one for it's weird scaling issues (probably because it is meant for different purposes - ie. integrating UI elements into 3D scene space), and second, the overlay just generally feels safer in terms of placement and anchoring. I also don't want to use screen space - camera. There is no camera in the additive scenes and I would like them all being rendered by the top camera for performance reasons.

    What other options do I have?
    1. camera stacking is not working yet, also would require 2 cameras.

    2. render textures would help but that would require three cameras, right?

    3. I tried URP's Custom Renderer - Render Objects - to make the transition's layer render after everything. This gives the same result as using layer ordering within the sprites/canvases - specifically, it works only if the canvas is worldspace. Once it is an overlay, it's on top of everything. Also - why is this? Shouldn't the custom renderer just make the sprite render after everything? Is the Overlay Canvas a god or something?

    4. am I overthinking this and missing some simple and straightforward way? Also, why is this so complicated? Why can't a natural workflow exist by default - place a camera and make it render everything below in order of hierarchy, top to bottom, with natural transparency. Will this someday be possible?

    Thanks for any info or hints.
     
  2. Robber33

    Robber33

    Joined:
    Feb 22, 2015
    Posts:
    52
    I believe ui is not part of the pipeline yet, so currently its rendered seperately after everything else in the urp.
    i think this will come at certain point,
    not sure what your top layer would be, but perhaps an option would be render your top tilemap to a rendertexture and display it as a ui element ?
     
    Kazko likes this.
  3. Kazko

    Kazko

    Joined:
    Apr 2, 2014
    Posts:
    82
    That would explain a lot, I certainly hope that it's the case.
    I think I tried that as well, but it was with older version, and there was a problem with transparency of the texture. I will try again, though. Thanks!