Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs

Feature Request: Nested Masks

A topic by Scarlet String Studios created Jun 28, 2019 Views: 185 Replies: 9
Viewing posts 1 to 10
(1 edit)

Hi - just leaving a request here for something I was toying with recently.

If you use Unity's Mask component on an object and then add an Image as a child, you can peek at the shader settings to see how Ref, Comp, etc are auto-configured. I don't understand it fully myself, but I noticed that the STM UIMasked material stopped working when the object was placed in a nested mask (i.e. two of the object's parents had a Mask attached). I was able to fix this by poking around the editor and copying Unity's auto-configuration for what happens when I add an Image to a mask-within-a-mask. The material looks like this: 

This works for my use case. I have no idea how general it is, but I thought I should mention it since it would be a useful feature for the asset. At the very least, it looks like _MaskMode needs a range of more than 0-1, because every nested Mask that you add will have to write to another number.

Developer (1 edit)

Hey!

Thank you so much for finding this, another customer emailed me about this and I wasnt sure where to start looking for the answers. I can do a few tests and make this the shader's default settings if it all works out!
That bit about _MaskMode will need some experimenting for sure. I think I could potentially automatically set these values to what they need to be in STM's code that handles making temp materials...

Developer

So, I'm looking into this, and I can't seem to find those auto-configured shader values you mentioned? I don't see the values changing at all, so maybe I'm doing something wrong or misunderstanding what I'm looking for...? I'm also comparing my shaders to unity's default one again and trying to figure out what's even different between them that's causing these values to *not* auto-configure anyway. Either way, I'll make sure that the mask comparison value can be set to greater than 1 in the backend, for sure.

By "auto-configured", I meant something like this.


Above is a Text component added as a child of a nested mask, and below is a Text component added as a child of the top level mask.


And while we're at it, this is what the shader properties look like when I create a Text object without any parent masks.


Developer

Oh! These weren't showing in the super-ancient version of Unity I develop in, but I see them now!


I think I managed to come up with a solution for this! I still have your email, so I'm going to send you an updated build!

Developer

(The build worked! I think this should be out for the next update!)

Hey again, just bumping this with what appears to be a related bug.

It's hard to explain, but it seems that the nested mask doesn't work properly when objects are enabled/disabled. I tried to record an example in this clip. The bigger mask is the phone area itself, and the smaller mask is the chat backlog area. If I deactivate the object hierarchy with the chat backlog mask and then re-activate it, the child mask doesn't work and the STM object only responds to the first mask (you can see the text peeking out in between the backlog area and the phone area). Then if I deactivate/reactivate the STM object (or change anything inside of it), it updates/refreshes somehow and then it works properly.

Developer

Hmm… part of the masking code checks if STM’s gameObject is active in the hierarchy, or else it just gets ignored. Maybe the code is just getting run in the wrong order or something…? And yeah, like you found, an additional Rebuild() call would fix this. An additional call of ApplyMaterials() might work too, but I have that marked as a private method in the current build.

The masking code is called within ApplyMaterials(), which is called almost at the end of Rebuild(), which is called under OnEnable()… So it’s a bit confusing to me why this wouldn’t work right. Does it just happen when enabling/disabling objects in the unity editor, or with code, too? It might have to do with script execution order if it’s in-editor only?

How strange... yeah the original problem was likely related to exectuion order, but it looks like everything's working now? Actually, the issue might have been that I was using a material called UIMasked, and I can't remember if I made that myself or if it came with an older version of STM. Either way, I'm currently using the UIDefault material (because masking is built-in now) and it appears to be working. Could have been some obscure material setting messing things up.

Developer

Let me know if it happens again with the new shader! I believe those old shaders were hard-coded to work in a certain way, the new ones should behave more naturally with Unity.