A Unity ID allows you to buy and/or subscribe to Unity products and services, shop in the Asset Store and participate
in the Unity community.
Now in Beta! Get 1:1 live lessons on any Unity topic or help troubleshooting your project – Connect with an expert on Unity Live Help
Discussion in 'Assets and Asset Store' started by DominoOne, Feb 16, 2015.
Glad I could help And it's great that it was just a minor issue in your setup!
Another voice here requesting TextMeshPro support please.
An update for "Alpha Mask: UI, Sprites and Unlit 3D Objects" has just been rolled out. It introduces a multitude of new features:
- Added more thorough Documentation, which answers some frequent questions and explains new features, as well.
- Moved the masked shaders to the Resources folder, so that Unity would always include them in builds (NOTE: if you have two instances of each masked shader after the update, remove the old ones and keep the ones in the Resources folder).
- Added the possibility to easily change the Alpha Mask texture in run-time.
- Added the possibility to easily disable and enable the overall effect of an Alpha Mask.
- Added the support for standard Unity UI masks for the UI elements that are already masked with the Alpha Mask.
- Added the possibility to easily duplicate masked materials in run-time (useful when the masked hierarchy is duplicated or multiple instances of a prefab are used).
- Fixed an issue, where after applying a new Alpha Mask on Unity UI Texts, the texts would become black.
- Other minor improvements.
Do you think you could have time to make a step by step VIDEO tutorial on how to use your mask in prefab? (and also update the mask texuture in runtime.)
I think a video tutorial would definitely help people like me to understand exactly how to use it correctly.
I updated to latest version and followed your instructions from PDF but failed to make things work.
The masked objects are now even at the wrong position and i have to roll back.
My usage is to use the mask in a prefeb and have that prefab instantiate a lot of instances which its mask texture need to change to another shape when needed.
There was a small issue for some (or maybe most) cases of using DuplicateMaskedMaterials() and possibly ChangeMaskTexture(Texture texture). I have just submitted an update with that issue fixed, so let's hope it will reach the store early next week. Sorry about that!
Nickromancer, is it possible that you called commands in this order (within the same block of code):
If so, then it should start working after the update (let me know if you need the script earlier - I can send it to you directly).
OK, so the fix is out. Duplicating materials in prefabs should now work as intended, when they are duplicated right after instantiating.
I just stumbled upon this plugin for masking and I really really liked it.
Now I want to create a system where I want to reveal parts of the sprite on which the player drags the pointer. Like a coloring book game or like those kids game where water and foam are displayed as the player drags the finger.
That sounds great! Although, was that a question or simply an expression of joy?
Thanks for your interest in our plugin! What you're looking for can be achieved this way:
- Create a RenderTexture.
- Create a simple shader that always renders sprites in plain white.
- Make a duplicate of the nearest camera and make it's "depth" (order) earlier than the nearest camera. For this camera set the RenderTexture as its target texture. Set the white sprite shader as the replacement shader of this camera. Also set the camera clear color to black.
- Set the RenderTexture as the Alpha Mask of the black overlay that you have. In this step you can use our plugin
Hope that helps!
Hello, the alpha mask is bugged?? I have 2 similar projects. (The older one) works fine and uses alpha mask as intended. The new project which i copied without editting the alpha mask is not showing despite the mask having the same attributes as the older one. Is there a fix?
I've just checked, and there actually is a shader in Unity that you can use for that – "GUI/Text Shader". So, no need to create a new shader, you can do everything with what you have (except Alpha Mask, which you still need to get)
Could you elaborate what goes wrong and how exactly it looks in the broken project? I'd be glad to help, but it's very hard to say anything without knowing the details
For the replacement shader you'll have to create a very simple script that does something like this on Start (if you want it to work in the editor, you can also make the script run in the edit mode) and assign it to the new camera that you've created:
Shader whiteShader = Shader.Find("GUI/Text Shader");
if (whiteShader != null)
Regarding your other question: if you have already purchased the plugin, there is Documentation that explains how to create the Alpha Mask, assign an image to it (in this case, the RenderTexture that you've created) and apply it to the other visuals. You can also see these steps in the video on the Asset Store.
Let me know if you need anything else
Copying sprites seems not to work, is that intended? And if yes: How can I change that?
Reproduction can be done in the sample scene -> Copy the Unity UI Sample GameObject and rotate the new copy, the alpha mask for the other one will be messed up.
EDIT: Turns out, it didn't read the manually until the end, however the method described there does not allow me to use my own shaders for the actual sprite. Is there a way around that?
I'm glad you found how to make it work in the end As for shaders, the Alpha Mask only works with the default ones, but you could probably copy your custom functionality from your own shaders to the masked shaders.
Thanks for the reply. Reimporting the asset fixed the issue. Thank you
Is it possible to create a mask from a custom mesh (generated on the fly) using this asset? If so, will I will be able to give it "soft" edges, so that there is a transition from on to off rather than a hard edge?
You cannot use a mesh as the Alpha Mask with our plugin directly – you need to have an image. However, you can render that mesh into a RenderTexture and then use it with our plugin. Also, when rendering to the RenderTexture you can apply anti-aliasing (RenderTexture has that functionality out of the box) or even blur (by using a full screen effect on the camera that renders the RenderTexture). This is not directly related with the functionality of our plugin, but I'm just explaining this to let you know that it's possible
Hi, I'm having a problem with the mask. It works well in editor but doesn't seem to work at all in build. I'm not sure if it is the plugin problem or i just screw up settings somewhere. When i tried to build it in development build, this error keeps coming up: Shaders necessary for masking don't seem to be present in the project.
However it works normally in Unity editor. Do you know how to solve the issue?
Hm.. I might know what the problem is, but it should have been fixed with one of the updates. Do you use the newest version of the plugin? If not, you should update. But if you're already using the newest version, could you try creating a Resources folder in the root of the Assets folder and then moving the shaders that are in the Alpha Masking/Resources folder to the root Resources folder? Let me know if that changes anything.
Thanks! I fixed the issue by moving the shaders.
Also, does the alpha mask works on TextMeshPro elements? I can mask the text UGUI but unable to mask the 3D text mesh element
As long as you use one of the two shaders – Unlit/Transparent or Sprite/Default – you can use the mask on those elements. However, TextMeshPro is using their own custom shaders (and about a dozen of them), so it's a little difficult to support them.
Now that Unity is planning to integrate TextMeshPro as a native text framework, maybe they'll clean it up We'll have to see.
Can this be used to mask 3D objects rather than 2D panels. i.e. have a 3D object in world space mask another 3D object in world space. The same as this old asset did?... https://www.assetstore.unity3d.com/en/#!/content/33978
If not, do you know of any asset that does manage this?
Our Alpha Mask does work with 3D objects, but only those that use the Unlit/Transparent shader. And there is a limitation that it can only be mapped over 6 axes (X, X negative, Y, Y negative, Z and Z negative), so if you need the Mask to move along with the Camera or render a perspective view, it won't work. So, all in all, from what I see it looks like our plugin is not perfect for you, but in some specific cases it would work absolutely fine with 3D objects
Thanks for getting back to me. Sounds like you are correct. I'm looking to be able to render objects only when they are inside a another object (sphere) and mask off the parts that are outside the sphere. Haven't found anything yet but if you know something I'd appreciate any advice or recommendations.
Unfortunately, I don't know of any particular plugins that do that.
This asset is wonderful! A couple issues I ran across though. First, I couldn't seem to set up a mask in runtime for quick testing. Secondly, I am not able to get a mask to work with uGui Images. I see it working in the demo though on my version. any chance you know what I'm doing wrong?
included is an image showing sprites working but not images, as well as the inspector foldout for the mask.
Thanks for the kind words! In your situation, I'm not fully sure what's happening. Are you using a "Screen Space - Overlay" UI canvas? It should work with this option, but it makes things confusing, as it doesn't map equally between the Scene view and Game view (e. g. I cannot see your Sprite in the Game view, which means that they're aligned differently, which might mean that the Mask isn't aligned with the UI, either). Also, could you try increasing/decreasing the size of the Mask within the canvas? Maybe it's just too small or large. Again, if you're using "Screen Space - Overlay" UI, you shouldn't look at the scene view at all, because Unity shows random sizes and positions there That's why I always recommend using "Screen Space - Camera" or "World Space" UI – it's much more intuitive.
I am using screen space - overlay. you are right, it does work I just had to move the mask down a bit for it to work. I think this little trick will work for me. I can't get around screenspace overlay so hopefully I can just make a positional map to keep it aligned. thanks for the quick reply!
Does the plugin perform well on mobile with the RenderTexture technique?
Great that it worked!
It shouldn't be a problem on mobile, but it all depends on how complex your Mask is. E. g. if you're only rendering a few soft masks into the RenderTexture, you can use a pretty low resolution RenderTexture – it should be pretty fast.
I added a mask to a prefab and instantiated it but the mask does not seem to apply and gives me the following error when I click on the mask object:
NullReferenceException: Object reference not set to an instance of an object
ToJ.MaskEditor.OnInspectorGUI () (at Assets/Alpha Masking/Editor/MaskEditor.cs:17)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1236)
are prefabs not supported?
I saw you walking someone through this earlier and was able to get the error to no longer show up following this thread:
Could you try following these steps:
1. Create the Mask and the Sprite that you will mask (as you have done already).
2. Manually create a material (within the assets) and assign the "Alpha Masked/Sprites Alpha Masked - World Coords" shader to it.
3. Drag this material into the material slot of the Sprite that you've created in step 1 (the one that you want to mask).
4. Create another material and assign the "Unlit/Transparent" shader to it. Also assign the Mask texture to this material.
5. Drag this material into the material slot of the Mask that you've created (on the Mesh Renderer of the Mask).
6. On the Mesh Filter of the Mask object choose "Quad" (the standard Unity mesh object) instead of the already assigned mesh.
7. Hit "Apply Mask to Siblings" on the object with the Alpha Mask. You should now see the Sprite being masked as it should be.
8. If everything worked so far, create a prefab from the hierarchy. You can now instantiate the prefab, and it should work as intended.
Please let me know if that works
so I'm closer to the solution. however the mask does not seem to effect anything yet.
I think I figured it out. I didn't have the sprite material set up properly.
Hehe, it's great that you managed to find help in my previous comments. And I'm happy that you made it work!
Does your plugin support inverse mask?
You mean cut a hole in a visual element? If so, then, yes, it definitely supports that You just need to make a mask, which has white edges and black middle.
I am trying to set up two objects with masks but I always end up with both objects using the same mask resulting in:
The mask image is always applied to one objects origin (right) so the other object gets the clamped alpha since the mask does not cover both objects (left).
Moving the mask moves it for both objects.
First I thought the problem origins from a shared prefab but also when I set up both masks independantly I end up with one actual mask for both objects. Using different materials also does not help. So maybe the problem is a shared mesh quad?
So the right object looks correct. The left one does not.
Any suggestion on how to fix this? This really is a problem for me right now.
Okay I found the solution. You have to set all the masked objects materials to None and then press "Apply Mask to Siblings..." button again. Then the object is independent of any other mask.
Maybe some code should be added if the used material is already used by another mask?
Also this is the result of using a prefab, maybe the code should also handle this?
I'm glad that you found the solution! Prefab instantiating in the Editor is a little difficult to handle, and materials are handled this way to make it more optimal. However, we're constantly thinking of how we could improve that, and sharing use-cases like yours always helps identify what the real-world situations are and what people actually need So, thank you for that! We have greatly improved prefab handling, when they're instantiated in run-time (there are a couple of sections in the Documentation about that), but we'll also see if we could improve instantiating in the Editor.
I encountered another issue. In the editor I apply the mask and all objects get correctly updated. The material is correctly assigned to the Image component. Once I press "Play", the material reverts back to None.
I added some logs to the mask game and editor script but could not find anything obvious.
EDIT: The issue seems to be related to the masked object being disabled in the Start() function. I noticed that when I deactivate an object the mask does not get applied which imho is incorrect, because the object is enabled during gameplay.
Do you have a suggestion what I could check for?
Hi again Dan,
I tried reproducing the situation from your description, but I couldn't... Would it be possible to get a project that demonstrated this flawed behavior? I would be happy to look at it.
I am very busy right now since I need to finish that project but I will send you something to reproduce my issues after that.
I just bought your plugin and I would like to know if it works with line renderers?
And does it works with sprites dynamically generated?
Yes, it works with Line Renderers And it works with dynamically generated Sprites, but a couple additional steps and/or lines of code might be needed. The Documentation should help with that, though (you can use prefabs if possible, and the Documentation has a section about instantiating masked prefabs).
hi, i try to mask UI camera on the BG sprite like this, above i using sprite masking on unity 2017.1, it work so good, but still not stable, error when i moving camera using render mode "screen space - camera" so your asset can make like above ?
Thanks your help!
Yes, our plugin can definitely do that