Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

UGUI 5.2: Rect Mask 2D has BUG! be careful

Discussion in 'Unity UI & TextMesh Pro' started by qiankanglai, Mar 11, 2016.

  1. qiankanglai

    qiankanglai

    Joined:
    Jun 8, 2013
    Posts:
    35
    Tested with Unity 5.2.4. Other versions should have this bug as well
    Bug submitted: https://fogbugz.unity3d.com/default.asp?778851_oh3pc9c7tb42fl40

    Reproduction steps:
    First put a Image under a RectMask2D
    [​IMG]
    Step 1: move this image out of this rect region
    [​IMG]
    Step 2: move this image into another RectTransform(without mask), resetting anchorPosition
    This image is still invisible (But no mask should apply to it now)
    [​IMG]


    Test scene has been attached (Just click step1, step2 button in screen)
    Dirty fix I found: force `CanvasRenderer.cull=false`
     

    Attached Files:

  2. JoaoPaul54

    JoaoPaul54

    Joined:
    Nov 20, 2013
    Posts:
    51
    I can attest to this bug... in my project, the only workaround I found was when an item is updated and I expect him to be out of the mask I would create a clone of it and delete the old one
     
  3. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    2,482
    This was fixed the other day. It should be in an upcoming fix but if you want it now you can download the UI source code and apply this change:

    Code (CSharp):
    1. diff --git a/Extensions/guisystem/UnityEngine.UI/UI/Core/MaskableGraphic.cs b/Extensions/guisystem/UnityEngine.UI/UI/Core/MaskableGraphic.cs
    2. --- a/Extensions/guisystem/UnityEngine.UI/UI/Core/MaskableGraphic.cs
    3. +++ b/Extensions/guisystem/UnityEngine.UI/UI/Core/MaskableGraphic.cs
    4. @@ -91,6 +91,11 @@ namespace UnityEngine.UI
    5.                  return;
    6.              var cull = !validRect || !clipRect.Overlaps(canvasRect, true);
    7. +            UpdateCull(cull);
    8. +        }
    9. +
    10. +        private void UpdateCull(bool cull)
    11. +        {
    12.              var cullingChanged = canvasRenderer.cull != cull;
    13.              canvasRenderer.cull = cull;
    14. @@ -196,7 +201,10 @@ namespace UnityEngine.UI
    15.              var newParent = (maskable && IsActive()) ? MaskUtilities.GetRectMaskForClippable(this) : null;
    16.              if (newParent != m_ParentMask && m_ParentMask != null)
    17. +            {
    18.                  m_ParentMask.RemoveClippable(this);
    19. +                UpdateCull(false);
    20. +            }
    21.              if (newParent != null)
    22.                  newParent.AddClippable(this);
     
  4. qiankanglai

    qiankanglai

    Joined:
    Jun 8, 2013
    Posts:
    35
    Got it, thanks. Waiting for Unity updates with this fix.
    Currently I'm avoiding this by modifying my own project code, rather than UGUI source (Though the latter one is easy to fix in source, it is quite annoying to apply my modified UGUI dll files)
     
  5. qiankanglai

    qiankanglai

    Joined:
    Jun 8, 2013
    Posts:
    35
    In fact there is an easy way: just force setting `CanvasRenderer.cull=false` for the object outside mask...
    no need delete and new again :D
     
    karl_jones likes this.
  6. JoaoPaul54

    JoaoPaul54

    Joined:
    Nov 20, 2013
    Posts:
    51
    Awesome :) Both the fix and the "way less horrible" workaround :)

    I'm updating my code with this workaround and wait for the patch to hit Unity as I cannot use the source code (company GIT and so on... :/ )
     
  7. Shadeless

    Shadeless

    Joined:
    Jul 22, 2013
    Posts:
    133
    @karl_jones
    Just found this thread and I have a similar issue.
    Using Mask works for me but using RectMask2D doesn't work in Play Mode for some reason.
    Basically set the scene up so UI elements aren't visible from the Mask. Then enter Play Mode and modify the RectMask2D Rect Transform so they become visible (I modified the size), but they don't show up. They remain culled I guess?

    Anyway just wanted to tell you about it. I'm using 5.5.0f3 btw.
     
  8. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    2,482
    The original bug was fixed last year. It sounds like you have found something new. Can you file a bug report please?