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

RawImage not respecting Mask in Scroll Rect

Discussion in 'UGUI & TextMesh Pro' started by WarrenB, Mar 12, 2015.

  1. WarrenB

    WarrenB

    Joined:
    May 24, 2012
    Posts:
    21
    I am using Unity UI on version 5.0.0f4 to create a scrollable user interface on a phone.

    .Canvas
    .....Scroll Rect (scroll rect script and mask script)
    .........Content
    .............RawImage
    .............Text

    I have used a similar setup in other places and it seems to work well. The Scroll Rect allows the user to scroll through all the children of the Content object. The Mask script on the Scroll Rect prevents the content from being displayed outside the visible area of the scroll rect.

    However, the mask is not masking out the Raw Image. The image is rendered even when it scrolls outside the Scroll Rect masked area. If I scroll far enough for the text to go out of bounds I can see that the mask does prevent the text from being rendered. Why not the Raw Image? Is this a bug? Is there a workaround?
     
    Last edited: Mar 13, 2015
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    Hmm, it could be because the RawImage is a Texture2D and not a sprite. However since RawImage is part of the UI framework you would expect it to work.

    @phil-Unity @Aras any ideas?

    Should this be logged as a bug or is it by design?
     
  3. WarrenB

    WarrenB

    Joined:
    May 24, 2012
    Posts:
    21
    I see my indentation didn't take. I tried again with periods to show parent/child relationships.

    I can provide a Unity package if that helps.
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    Is there a non-default Material set on the RawImage? I believe that the RawImage's shader would have to be the shader that incorporates 'being masked', so materials other than the default probably would break it.
     
  5. WarrenB

    WarrenB

    Joined:
    May 24, 2012
    Posts:
    21
    Thanks, StarManta.

    The material says "Sprites-Default"

    If I change it to None then the image does mask! Curious. Does that sound right? I'm wondering if that will work dependably. That test was in the editor. I will check on Android and iPhone when I get new builds through.
     
  6. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    Yeah, that was probably it. The Sprite material isn't intended to be used in the UI system, it's meant for in-game sprites, which means it very likely simply doesn't support masking. When I create a (working) RawImage under a Mask, it does have (None) set as the material.
     
  7. iLyxa3D

    iLyxa3D

    Joined:
    Sep 25, 2013
    Posts:
    31
    Looks like a bug
     
    gdarie likes this.
  8. Maisey

    Maisey

    Joined:
    Feb 17, 2014
    Posts:
    300
    This is known (bug?) to me, but would be nice to know if this is intended.
    I have a lot of UI using Sprites-Default.
    1. Because same material results in less draw calls if textures in same Atlas.
    2. I think I benchmarked it sometime and it was more effective (probably since it doesn't need to mask)
    But stuff in ScrollRects that needs cropping we leave "blank" (AKA none).
     
  9. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,738
    It's not so much that this is intended, more that it is the result of using the components/materials in an unintended way. That is, the UI elements aren't expected to use the Sprite shader.

    (It's entirely possible that features like masking support are the very reason that the default UI shader could be more efficient than the Sprites shader.)
     
  10. paulw_cloudhead

    paulw_cloudhead

    Joined:
    Dec 14, 2016
    Posts:
    1

    If you make the minimap ( RenderTexture, etc. ) image a child of the mask image ( sprite works fine ), you don't have to mess with setting any materials. The process isn't clear because for non-raw images, the sibling order in the hierarchy is what determines the mask.