Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Masking Text Fails if Mask's GameObject SetActive toggled.

A topic by digiwombat created Dec 07, 2020 Views: 312 Replies: 5
Viewing posts 1 to 4

I couldn't find anything on the forum for this so if I missed it, I apologize.

Just to cover the first bit, the shader is set up to properly use masking per other posts on the forum (Mask Comparison set to 3) and it works properly in general.

I have a Hierarchy that looks like this Tablet -> ContentArea (Mask) -> PlayerInventory -> SelectedItemName (The STM GameObject)

If I toggle either the Tablet or the ContentArea (Mask) GameObject off and back on, the mask stops working. It seems like the only thing bothered by this is the mask interaction.

A rebuild of any kind seems to solve the problem so I currently have a script to fix it up but obviously I'd prefer to have it working without the script being on every mask-interacting STM instance. Haha.

Also, for some reason, for Outline and DropShadow shaders, text preview only shows the shadow or the outline, not the text. I'm on URP with the 2dRenderer so if you tell me that's to blame, I will 100% believe you and apologize for even mentioning it.

Example: 

Should be white text with a shadow underneath.

Thanks again for your time! :D

Developer

Hmm STM should automatically mask properly without needing to edit the mask comparison value in the material's inspector, but I'm glad that feature still works, at least. I wonder if that could be causing the problem...?


STM is meant to call Rebuild() upon OnEnable() already, so... I wonder if it's somehow getting the values incorrectly on the very first frame...? Maybe STM is being reactivated before the lower objects int he scripting order, causing it to ignore that...? Before I dig deeper into this, try setting STM's masking mode through the STM inspector itself. I wonder if that value could be getting confused somewhere. Look for the "maskMode" dropdown, and you should be able to select "Inside" or "Outside" and it should automatically do it's thing if placed inside a UI mask. (But not a RectMask2D yet, apparently) Please let me know how that goes!


Unfortunately, outline and dropshadow aren't currently supported via shaders in URP, since URP doesn't support multi-pass shaders for whatever reason. I'm still working on a proper solution, but until then I have this script which creates the same effect if attached to an STM object: https://pastebin.com/ixxVjtCH

OKAY! I figured it out. I think. I went diggin' around in the code and threw in a million Debug.Logs() in the OnEnable because I am a man of deep talent and skill.

What I discovered was that this is just an unfortunate case of ScriptExecutionOrder and SuperTextMesh happening to run before the Mask. Upping the SEO on SuperTextMesh solved the problem and everything's fine. So if anyone else has a problem where things are having a hard time dealing with Masks, there ya go.

As to the outline, yeah, I figured it was URP. Sadly, I love those 2D Lights and how much time they save me. Interestingly enough, STM works perfectly normally in-game, the preview problem is limited to the editor, which is such a minor issue as to not be worth caring about for me. I'll keep that script handy in case I run into issues later on.

Developer

Ah right! I forgot that I was told that by a customer... keeping track of all this is a bit much sometimes, sorry.

That's unfortunate that the ScriptExcecutionOrder is like that, so... I'll note this in the docs in the future!

This solved a problem for us! Good find :-) But combining this with a layout group seems to place the component weirdly! I think it's because the placement is done BEFORE the enable on SuperTextMesh now. Is there a SEO that is like the "golden" value? :-P

Developer

I'm not too sure yet! I haven't actually reproduced this myself, but if you email me a sample project, I can get to hunting for it.