Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Text Disappearing Inconsistently when Enabling/Disabling Canvas

A topic by PeterEldredge created 29 days ago Views: 85 Replies: 7
Viewing posts 1 to 8

Hey All,

I am running into an issue where the text in my game seems to be disappearing at seemingly random or at least inconsistent times. I believe that it has to do with enabling/disabling the canvas, particularly in an animation, but I am not 100% sure if that is the case. This has been an issue for me since I started using the asset, and I have not been able to reproduce the issue in a consistent way.

Is there a caveat for using this asset I am missing? Or any ideas at a possible work around. I can't provide specifics about the game or screenshots, but I can give some more details about the setup if that would be helpful.

Developer

Hello!


Yeah, that shouldn't be happening... Hm a few things that come to mind from this scenario are...


1. Re-enabling the canvas might not be properly telling child STM objects to re-appear/re-make their meshes. Is this behaviour any different when the GameObject the canvas is on is turned on/off instead? Not sure if I already is, but need to check since this can narrow it down! (If this is the case, will look into why STM isn't updating in this scenario, but that's a quick working fix for you) I have a few  ideas on how to fix this if it's the problem.

2. Inside of an animation, please enable the "forceAnimation" variable on the text, at least for the frames where it will appear/disappear. This was intended as an optimization feature for animating text, but if a parent object is being set active/inactive, I can see the text or certain animations refusing to play. You can also try disabling "autoRead" or enabling "rememberReadPosition"... Those variables are true by default so if I had to guess, it's probably trying to read but refusing to automatically animate during the animation triggering it.


So, please give those a shot! setting the canvas's gameobject active/inactive, and enabling "force animation" on STM.

I have tried the two solutions that you provided but they did not resolve the issue. However, I did some more testing and my initial guess as to what the issue was is wrong.

The first thing I found was that it is almost an asset wide issue that happens when the bug occurs. It's not just the STM on the canvas that is being animated that can disappear.  Even STM on other canvases, in other scenes, that have no connection to the animated canvas can disappear at the same time.

I then narrowed down an instance of the issue happening to an animation event that I had on the animation, as it would happen whenever the event was present but did not reoccur after I removed it. The animation event triggered some code that would enable Game Objects that have STM components in their hierarchy.  These Game Objects are children of a canvas that's Game Object is enabled over the course of the animation.

I tried multiple things to resolve the issue, such as removing the animation event and enabling the Game Objects in code manually before playing the animation, moving the animation event until after the Canvas's Game Object was active, and setting the Canvas's Game Object to be active for the entirely of the animation. However, even if these solutions worked once, upon triggering the animation multiple times it would normally break again.

Because of this new information, my best guess is that it has something to do with setting an STM component active when a parent Game Object is inactive, or maybe that in combination with the animation system is causing a sequence issue. It is also really strange that it affects even completely disconnected STM components. Although, if there are shared systems or data between all STM components then maybe that could help narrow down the root of the issue.

While I could maybe find a work around to this problem by just blindly trying stuff until something works, I really would like to either get a solution or understand the issue enough that I'm not guessing at least. Any help you could provide would be greatly appreciated. Sorry that I can't show the game/problem directly, but I can give more details if that'd be helpful and can maybe try to replicate the problem in a different context if necessary.

Developer

Right, a few updates ago I remember changing the behaviour for enabling STM while a parent gameobject is inactive... 


Are you enabling the STM component, or the entire GameObject it's on in this scenario? Or does it not make a difference between the two? Confirming this will help narrow down the issue greatly - I see some points in the code where I'm only checking for one of these. This and the fact it's happening to all STM objects makes me think it's some type of desync with the internal materials system. 

Do all the effected meshes have the same font and material? Or do they have different settings? If it's only happening to a specific font, that would mean it's related the materials system for sure, which automatically makes text meshes with the same settings share internal materials.


The materials system is basically... Upon rebuilding, STM objects will create and use a cache of materials to render, not the actual material assigned in the inspector. I think toying with these created materials could also cause problems, but I'm not sure how they'd be getting edited externally here. Could there be code in your project that's somehow effecting created materials...?


For the animation event you're talking about, does this refer to a Unity animation event, or STM's drawAnims and event tags? Another guess is... if it's not forceAnimation not being enabled, it could be another variable that's being set automatically. Are you only enabling/disabling the STM object? What is being called in the animation event exactly? With autoRead disabled, I believe it would still call Rebuild() and if the mesh has a readDelay above 0, it would idle on frame 1. (I still don't think it's this but more detail is good!)


Also, what version of Unity are you using? I just remembered that Unity 2019 specifically had some issues with rendering multiple materials on a canvas which I was forced to eventually give up on after seeing it worked fine in 2018 and 2020.


Thank you so much for your patience by the way, I understand how it is to have an issue you can't really show off, so I hope this is at least making a bit of progress!

Hey thanks again for the quick response. I did a few more tests and have some answers to your questions, so hopefully they will help narrow it down. I am using Unity 2022.3 btw.

The Animation Event that was being called was just a Unity Animation Event in Unity's Animation system. That seems to be mostly unrelated beyond it just being a timing issue, as the issue did continue to happen in some of my tests where I just moved the functionality of the event to before the animation even played and got rid of the event entirely.

The code that is causing the issue simply enabled several Parent Game Objects that each have 1 or more STM components on Child Game Objects of that Parent. I did do a test where the Parents were always active, and I simply enabled/disabled the STM components instead of any Game Objects. Doing this did result in the error occurring still, so it seems like the issue can occur any time that the STM component is enabled, not just their Game Object.

The most important thing I discovered however seems to be that your guess about the material system being involved is correct. As mentioned in my previous message, the text on a completely separate STM component, that is always active and in an entirely different scene with no custom functionality/animation on it, would disappear as part of this issue. It did use the exact same font/material as the STM components on the Game Object I was enabling, however.  So, I tried changing only the font, and the issue did not occur on that piece of text (it stayed visible and no longer disappeared). Then I tried changing only the material, and the same thing happened, no issues. 

So to sum it up, the issue happens regardless of enabling the Game Object or the STM component directly. I am not changing any of the values on the STM component programatically, I'm just simply enabling a Parent Game Object. And the issue that occurs seems to specifically be that objects with the exact same material all can disappear, regardless of how they are connected or what canvas they are on.

Thanks again for the help with this issue and let me know if you need any more information.

Developer

Hm, I wonder if it could be...

Please try opening SuperTextMesh.cs, and replace every instance of "t.gameObject.activeInHierarchy" with "isActiveAndEnabled". It could be an inconsistency between active and enabled states, where I really should be requiring both at all times. There's a check for this related to the materials system too, but I'm not sure if it's the cause immediately.


And OK that's great to confirm it's the materials system. When the font or material is different, it's fine... Hm I did do some changes a few months back to code there that determines if two materials can be shared, I wonder if there's a value that's not being considered yet that could be causing the old material to be overridden by the new one, breaking the old text. Do you have a material that's being used on both UI and non-UI text? (This technically should be fine, but I could have messed up some values related to stencils, here:) 


Try uncommenting this code that's around line 7475:

//does masking value match
//if(MaterialExists_material.uiStencilDepth != Submesh_stencilDepth)
//{
//  continue;
//}


I removed this check for stencil depth since stencil ID *should* be enough to determine the materials  are different, but perhaps I over-optimized and it's actually required.


If it's neither of these, I'll keep poking around. I feel it's got to be code *like* the commented code above, some value I should be checking that I'm not.

Replacing  gameobejct.activeInHierarchy with isActiveAndEnabled actually worked! As far as I can tell the problem has been resolved in every case I noticed it before, and I haven't seen any side effects.

Thanks for the help in resolving this! I really appreciate you getting back to me so quickly. If possible, it'd be nice if there was an official patch at some point, but no big deal there as it's a pretty easy fix once you know what the problem is.

Developer

Lovely! Will make sure to get this updated in a build asap!