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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to create a mask.

Discussion in 'UGUI & TextMesh Pro' started by alt.tszyu, Aug 22, 2014.

  1. alt.tszyu

    alt.tszyu

    Joined:
    Nov 12, 2013
    Posts:
    110
    Anyone know how to do the mask at around 24:11 in this video

    The current build doesn't seem to expose the same Mask values. In the docs for Mask, it says this, "By using this element any children elements that have masking enabled will mask where a sibling Graphic would write 0 to the alpha buffer."
    So I created a script for the TitleBar and referenced the Image script, and set the maskable property on the Image script to true, but it still doesn't work. What am I still missing?

    edit:Well it seems the Image maskable property is set to true by default, so setting it to true by hand does nothing.
     
    Last edited: Aug 22, 2014
    rakkarage likes this.
  2. alt.tszyu

    alt.tszyu

    Joined:
    Nov 12, 2013
    Posts:
    110
    After hours trying to figure this out, apparently you just have to add an Image script and a Mask script to the object that you want to be the Mask. <facepalm/>
     
    Tim-C likes this.
  3. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,194
    Yes, we decoupled the mask from the other elements. Now any graphic can be a mask!
     
  4. GiantGrey

    GiantGrey

    Joined:
    Jul 2, 2012
    Posts:
    261
    having problems here with masks! When using them on a standalone build they work as expected. But as soon as i switch to android in the build settings the masks are broken. I tried to deactivate an reactivate the game objects but nothing.... only switching back to standalone fix this.

    Anyone else having the same issue?
     
  5. JasonBooth

    JasonBooth

    Joined:
    Jan 27, 2014
    Posts:
    623
    I had one today where my hierarchy was like so:

    Canvas
    ---Panel
    ------Image (with mask)
    ---------Item
    ---------Item
    etc...


    When the mask was on the image, it masks out everything below it regardless of where it is vs. the image rect. However, if I move it up to the panel, then it works fine.

    Seems like there's a lot of loose ends and 'special magic combinations' you have to understand with this system (Like the fact that mask needs an image component to work even though you don't intend to draw the image). I've spent most of the day trying to make a simple combo box, and will likely need to spend another day or two yet.
     
  6. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,194
    You need to make sure you have the project configured with a 24 bit depth / 8 bit stencil buffer. It's in the android player settings.
     
  7. adhdchris

    adhdchris

    Joined:
    Nov 13, 2013
    Posts:
    45
    While the 24 bit depth did the trick on newer android devices but testing the mask on a Galaxy Nexus resulted in only the mask image being shown.
     
    eridani and rakkarage like this.
  8. GiantGrey

    GiantGrey

    Joined:
    Jul 2, 2012
    Posts:
    261
    well that would be bad if it only supports newer phones.
     
    rakkarage likes this.
  9. adhdchris

    adhdchris

    Joined:
    Nov 13, 2013
    Posts:
    45
    Yeah that'd be a show-stopper, but it's not all bad. Apparently the mask still works on older phones however it also shows the mask graphic on top even if the option's unchecked. Using a transparent image for the mask works as a temporary solution though.
     
    rakkarage likes this.
  10. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    that seems to hide all the children too?

    no matter if i use "None (Sprite)" with color set to transparent, or a new transparent image
     
    Last edited: Sep 13, 2014
  11. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    "You need to make sure you have the project configured with a 24 bit depth / 8 bit stencil buffer. It's in the android player settings."

    i can find a setting for 24 bit depth buffer it defaults to on anyway
    but where is the 8 bit stencil buffer setting?

    Untitled.png
     
  12. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    Same for me here. Masks only show the mask image (and not the masked objects) on the Galaxy Nexus running Android 4.2.2. This is for Unity 4.6 RC1, and the 24 bit depth has been set.
     
    asofron and rakkarage like this.
  13. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    ya just tested again with rc1 and my simple mask still does not work on my galaxy nexus?
    i wonder if this is a galaxy nexus problem or a mask problem
    does anyone have an issue open for this?
    thanks