Search Unity

Alpha Mask: UI, Sprites, Tilemaps, Particles, 3D

Discussion in 'Assets and Asset Store' started by DominoOne, Feb 16, 2015.

  1. natsupy

    natsupy

    Joined:
    Feb 5, 2016
    Posts:
    17
    http://i.imgur.com/2q13C4V.gif
    uhm so can teach me how to can do like this with ur plugin, this is using 2017.1, but it have issue with event system when use "screen space - camera", i hope your help.
     
  2. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    Hm.. Did you mean that it gives an error when you use our plugin? Could you paste the error to me (you can send me a private message, and we can continue there)? :)
     
  3. natsupy

    natsupy

    Joined:
    Feb 5, 2016
    Posts:
    17
    oh no, error i said, it happen when i using mask have on unity 2017.1.xx, and with your plugin i dont how to mask like that
     
  4. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    Very sorry for a late reply! It's been a hectic period in our studio, since we're releasing our game :)

    Have you followed all of the steps in the Documentation that describe how to set up the Mask? Which step causes problems on your side?
     
  5. philip368320

    philip368320

    Joined:
    Dec 8, 2016
    Posts:
    4
  6. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    Hi philip368320,

    I haven't tested it, but I don't know why it shouldn't, as long as you use the Sprite/Default or Unlit/Transparent shaders :)
     
  7. tridentcanadainc

    tridentcanadainc

    Joined:
    Mar 8, 2017
    Posts:
    10
    Hi DominoOne,
    Great plugin! I like it a lot.
    Just a small problem I'm facing - I'm using several masks in different gameobjects (not simultaneously, but one by one - think of a tutorial for a game). I anchored the position of the mask using a rectTransform. It all looks great in the editor with all kind of resolutions, but when I build it to Android & iOS I see there are small movements and the masks are misplaced.
    All other gameobjects in the same hierarchy are placed correctly.
    My canvas is rendering "screen space - camera" and the materials are placed several dirs under "Resources".
    Any idea what could go wrong?
     
  8. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    Hi tridentcanadainc,

    Thanks for the kind words, it means a lot! :)

    Are the shaders (not materials) placed under Resources, too? And not within the Alpha Mask directory, but in a home Resources folder?
     
    tridentcanadainc likes this.
  9. tridentcanadainc

    tridentcanadainc

    Joined:
    Mar 8, 2017
    Posts:
    10
    OMG, for some reason I thought you said the materials should reside under Resources... moved the shaders to there - BOOM! works like a charm.
    BTW - why don't you just place the shaders to the Resources dir in the first place, on importing?
    Thanks!
     
  10. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    With one of the updates I actually moved them to the Resources folder within the Alpha Mask directory. In the documentation, Unity says that it can be anywhere (https://docs.unity3d.com/ScriptReference/Resources.html), but apparently, that's not true, and only the Resources in the home Assets folder are actually included in builds :) Not sure if this is a bug or if I misunderstood something, but it's pretty weird.
     
    tridentcanadainc likes this.
  11. tridentcanadainc

    tridentcanadainc

    Joined:
    Mar 8, 2017
    Posts:
    10
    Hi again,
    When running the alpha mask component with a TextMeshPro component in one of the siblings I get this error as soon as the object with the TMP component is enabled:
    Code (CSharp):
    1. UnassignedReferenceException: The variable m_sharedMaterial of TMP_SubMeshUI has not been assigned.
    2. You probably need to assign the m_sharedMaterial variable of the TMP_SubMeshUI script in the inspector.
    3. UnityEngine.Material..ctor (UnityEngine.Material source) (at /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/ShaderBindings.gen.cs:262)
    4. TMPro.TMP_SubMeshUI.CreateMaterialInstance (UnityEngine.Material source) (at Assets/TextMesh Pro/Scripts/TMP_SubMeshUI.cs:739)
    5. TMPro.TMP_SubMeshUI.GetMaterial (UnityEngine.Material mat) (at Assets/TextMesh Pro/Scripts/TMP_SubMeshUI.cs:718)
    6. TMPro.TMP_SubMeshUI.get_material () (at Assets/TextMesh Pro/Scripts/TMP_SubMeshUI.cs:65)
    7. ToJ.Mask.Update () (at Assets/Alpha Masking/Mask.cs:233)
    8.  
    That is after I've changed all Mask instances in TMP to use UnityEngine.Mask to avoid using Alpha Mask's Mask Class.
    How can this be fixed please?
     
  12. senkenc

    senkenc

    Joined:
    Jul 2, 2017
    Posts:
    2
    Hi, would you please send me the sample code about how to use it from a prefab or a new instance?
     
  13. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    tridentcanadainc,

    I'm not 100% sure how TextMeshPro works, but you could try replacing lines 233 and 423 in the Alpha Mask's Mask.cs file with this line:
    Code (CSharp):
    1. if (!(UIComponent is TMPro.TextMeshPro) && (!differentMaterials.Contains(UIComponent.material)))
    Let me know if that helps.
     
  14. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    senkenc,

    It's pretty straightforward :) Somewhere, where you're instantiating the masked hierarchy, do something like this:
    Code (CSharp):
    1. GameObject instantiatedMaskedHierarchy = Instantiate(maskedHierarchyPrefab);
    2. instantiatedMaskedHierarchy.GetComponentInChildren<ToJ.Mask>().DuplicateMaskedMaterials();
    Let me know if that clarifies things.
     
  15. tridentcanadainc

    tridentcanadainc

    Joined:
    Mar 8, 2017
    Posts:
    10
    Well, I actually made an exact workaround but with a different type:
    Code (CSharp):
    1. TextFx.TextFxTextMeshProUGUI
    I will also add your suggestion.
    It works well, thanks a lot! :)
     
  16. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    tridentcanadainc,

    I'm glad it works! :)
     
  17. tridentcanadainc

    tridentcanadainc

    Joined:
    Mar 8, 2017
    Posts:
    10
    Hi, looks like I rejoiced too fast...

    Your code change (and also mine) eliminates this error but completely screwing up the masking placements...
    It is now being misplaced for all resolutions except one...
    Can you think of any other solution please?
    Thanks.

    EDIT: forgot to mention that as soon as I remove the "fix", all masks are getting placed correctly again, in all resolutions.
     
  18. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    tridentcanadainc,

    Is it possible that the TextMeshPro object is the first object in the masked hierarchy? Could you try moving it down, so that other UI elements would be first, and TextMeshPro would go afterwards? Does that help?
     
  19. tridentcanadainc

    tridentcanadainc

    Joined:
    Mar 8, 2017
    Posts:
    10
    Looks like combining your latest suggestion with the addition to the if-statement do the trick.
    For now it looks alright, I'll report if I'll catch something bogus.
    Many thanks!
     
  20. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    tridentcanadainc,

    Sounds great! :)
     
  21. senkenc

    senkenc

    Joined:
    Jul 2, 2017
    Posts:
    2
    Thanks for reply! However, I tried DuplicateMaskedMaterials after instantiate, but it's not working. The new instance still do not have a material masked. Please help...
     
  22. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    senkenc,

    Sorry for a late reply, I was on vacation for a few days :)

    It sounds to me that you haven't applied the mask to the hierarchy before you created the prefab. Because you need to make sure that the elements in the Mask hierarchy are masked, and only then create the prefab. And then when instantiating, call the mentioned line to duplicate materials. Or is my guess wrong?
     
  23. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    Hello,

    I am very happy to announce that Alpha Mask v2.0 has just been released! It includes a major rework of the code and usability. What's new:
    • Highly improved usability.
    • Much easier prefab usage.
    • Free rotation of the Mask, not restricted to any axis.
    • Improved performance for Sprites.

    Note that after updating the plugin, your masked elements will be updated to work with the new version, but it's still recommended to backup before the update, just in case :)
     
  24. IvanAlvarez

    IvanAlvarez

    Joined:
    Apr 30, 2013
    Posts:
    7
    Hi,
    I have a scroll rect that gets populated at run time. I would like to mask the content of that scrollrect, but right now you need to use the apply masking button in the editor.

    So is it possible to do this at runtime?
     
  25. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    Hi IvanAlvarez,

    The easiest way to do this is to add one element to the list in the Editor, apply the mask and then create a prefab of that element. Now you can populate the list at runtime using that prefab – the elements will be masked properly :) Does that help?
     
  26. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,321
    Hi. Can this be used to soft edge mask sprites from sprite sheets?
     
  27. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    Hi eco_bach,

    Yes, our Alpha Mask supports and masks packed Sprites, if that's what you mean :) And yes, it's possible to have a soft edge (actually, any grayscale texture works as a Mask).
     
  28. dis-s

    dis-s

    Joined:
    Mar 25, 2013
    Posts:
    45
    Hi!
    I am interested in your mask component. Can you tell me if it suit my needs?
    I need the following:
    Mask.jpg

    I need to apply some emboss or shadow to the result of masking. Is it possible with yoyr component?

    Is your mask works with UI Shadow or UI Outline? (the standard Unity mask does not work).

    What solution can you suggest?
     
  29. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    Hi dis-s,

    Thanks for your interest! Our Alpha Mask works with Unity UI Shadow and Outline, but not in the way you're looking for :) The Mask will actually mask the shadow and/or the outline, along with the UI element itself.

    I suppose you could do this:
    - Make a masked element with the image you need.
    - Make a second masked element (with a separate Alpha Mask in the hierarchy) with a black semi-transparent image.
    - Shift the second Mask along with the black image a bit, so that it looks like a shadow.

    The shadow won't be blurred, but neither would Unity's own UI Shadow. I hope that helps!
     
  30. dis-s

    dis-s

    Joined:
    Mar 25, 2013
    Posts:
    45
    Thanks for the answer! So, no workaround for the emboss?

    You have great Text Effect component, it works great with the text but unfortunately it does not support UI images. I'd like to offer the feature request to make the bevel/emboss/shadow component which can work with images also (especially with masked images). I would be happy to buy such component. :)
     
  31. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    Hi dis-s,

    Here's what you can do with our Alpha Mask :)

    - Make a masked element with the image you need.
    - Make a second masked element (with a separate Alpha Mask in the hierarchy) with the same masked image, but assign its UI color to gray (it will make the image darker).
    - Shift the second Mask (but not the masked object itself), up and to the left a little.
    - Make a third masked element (with a separate Alpha Mask in the hierarchy) with a similar masked image, but the image should be brighter (you can simply create a new copied asset for that).
    - Shift the third Mask (but not the masked object itself), down and to the right a little.
    - Move the second and the third masked objects back, so that they're behind the main masked object.

    This will create a pretty nice inner bevel effect. It requires an additional image, but otherwise it's quite straightforward. Let me know if this solution would help :)
     
    dis-s likes this.
  32. dis-s

    dis-s

    Joined:
    Mar 25, 2013
    Posts:
    45
    Thanks for the great idea! I will try it.
     
  33. VTOLEE

    VTOLEE

    Joined:
    Oct 13, 2014
    Posts:
    3
    Hi, i got build error when trying to build standalone on Unity 5.6.2f1 on Mask.cs :-

    Assets/Alpha Masking/Mask.cs(381,8): error CS0103: The name `maskVersion' does not exist in the current context
    Assets/Alpha Masking/Mask.cs(383,5): error CS0103: The name `VersionUpgradeMask' does not exist in the current context
    Assets/Alpha Masking/Mask.cs(384,5): error CS0103: The name `maskVersion' does not exist in the current context

    what could be the problem ?
     
  34. siamon

    siamon

    Joined:
    Apr 14, 2015
    Posts:
    7
    actually i have exactly the same error(im using unity 2017.1.1f1 though)

    edit: it works in the editor when i play it, but when trying to build it it just fails.
    Could it be JDK issue? i am using the latest one (JDK1.8.0_144) i remember that last time i had simmilar issues with plugins it was that. Could you please investigate - thanks

    edit2: i also tested this in a blank project, just this asset imported...not even added to the stage or anything. Building for android fails.
     
  35. VTOLEE

    VTOLEE

    Joined:
    Oct 13, 2014
    Posts:
    3
    so does any 1 facing issue like this? any possible solution? would be great if someone know about it.
     
  36. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    Hi,

    Sorry for this – there's a little bug in the plugin itself. We've just submitted an update to the Asset Store, but it might take a while until it's public. So, if you need it ASAP, please send me a private message with your invoice number, and I'll send you the updated package.

    Thanks for notifying about the issue!
     
  37. KhenaB

    KhenaB

    Joined:
    Aug 21, 2014
    Posts:
    267
    Hey there,

    Interested in the plugin mostly for the multiple mask feature, however i want to know if it is possible to have sprites render over the shadow to make it look like they are glowing in the dark, but also have them render behind other sprites that are behind the shadow, hope this makes sense.

    Thanks.
     
  38. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    Hi KhenaB,

    Thanks for your interest! I would love to help, but from your description I'm not completely sure what you mean. Could you make a visual mock-up of what you're seeking?
     
  39. KhenaB

    KhenaB

    Joined:
    Aug 21, 2014
    Posts:
    267
    Here's a mockup, the green square is behind the shadow and visible through the mask, the red sphere is rendered over the shadow yet it has a layer order lower than the green square so renders behind it. Mockup.png
     
  40. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    Hi KhenaB,

    Thanks, much clearer! Well, the masked sprites have almost all of the same features as regular sprites, but I'm not sure how to achieve this with regular sprites, either (if you simply used a black sprite with a hole in the middle – not masked, would you be able to recreate this view?).

    Although, there is a way to achieve this with masks:
    - Create an Alpha Mask for the black sprite, so that the middle would be transparent.
    - Make the green sprite render behind the black one.
    - Make the red one render in front of everything.
    - Add the default (sharp) Unity mask component on a sprite that duplicates the green sprite (or maybe you'll be able to add it to the green sprite itself) and apply that mask to the red sprite. You could probably also use our Alpha Mask to mask the red sprite, too, if you need a smooth Mask.

    Hope that helps :)
     
  41. everton

    everton

    Joined:
    May 28, 2013
    Posts:
    7
    Hi @DominoOne! How are you?
    Your work is great. I'm very interesting in buy it. I already had read that it works fine with Anima2D, but I have a doubt. We are developing a game similar to a Slot mechanic. Each slot have a few animation and it will need an individual mask. On the screen it will have 15 slots simultaneously, animated or not. Is this scenario ok to your component?
     
  42. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    Hi @everton,

    Thanks for your kind words :) We're doing our best!

    The situation you described sounds perfectly fine. And in case it completely fails (and we can't help you personally), you can always ask for a refund :)
     
  43. everton

    everton

    Joined:
    May 28, 2013
    Posts:
    7
    Thanks @DominoOne!
    Buying right now :)
     
  44. everton

    everton

    Joined:
    May 28, 2013
    Posts:
    7
    Hi, @DominoOne

    Can you send me a sample of use between your compoment with Mesh Renderer or Skinned Mesh Renderer (Anima2D). I haven't problem using simple animation, but if I try mask animation that uses bones, din't work :/
     
  45. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    Hi @everton,

    It's weird that it doesn't work. There are actually a few examples that use a MeshRenderer in the Samples scene. Have you checked them out? Have you followed the steps in the documentation?
     
    everton likes this.
  46. everton

    everton

    Joined:
    May 28, 2013
    Posts:
    7
    Hi @DominoOne ,

    The samples show cases using only MeshRenderer (the Ship one). Using just simple animation I have no problem. My problem will be using animation with bones, using both Skinned Mesh Renderer and Mesh Renderer, or just the Skinned Mesh Renderer.
    I have some bugs using Particle System also.

    Can you help me?

    Regards,

    Ps: I'm using the Unity 2017.2.03f
     
    Last edited: Nov 8, 2017
  47. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    Hi @everton,

    Skinned Mesh Renderers should work exactly the same as regular Mesh Renderers, unless Unity made some major changes in Unity 2017. Could you send me a private message with an image of what you're seeing in the editor (the setup of the Mask, the masked Mesh Renderer, etc.)? Without visual information it's hard to tell what goes wrong :)
     
  48. everton

    everton

    Joined:
    May 28, 2013
    Posts:
    7
    Sure!
    I just sent a messagem Inbox to you.

    Thanks
     
  49. kleinsan

    kleinsan

    Joined:
    Nov 8, 2017
    Posts:
    16
    Hi, I just bought your mask, and it looks like it can create the visual effect that I'm after. I'm just wondering if you know if it is possible to generate the mask used by the script procedurally at runtime?
     
  50. DominoOne

    DominoOne

    Joined:
    Apr 22, 2010
    Posts:
    415
    Hi @kleinsan,

    Thanks for buying it! :) Yeah, you can definitely use a texture generated in runtime. There is actually a sample in the package that uses a RenderTexture, dynamically modified in runtime.