First, TextMeshPro is a wonderful piece of work. Thank you very much.
Your answer worked well. However, I have two follow up questions.
Is there a way to toggle that boolean value through the inspector?
Now let’s say I have “Hello” as the initial string. In Awake() I set enableCulling to be TRUE. Now during runtime, if I add an emoji to it, say [😀 Grinning Face Emoji] - which in turn uses the default emoji sprite. The culling is absent for that emoji as it creates a new child called as “TMP SubMesh [TextMeshPro/Sprite]” with TMP_SubMesh component to it. How do I deal with it?
Do I have to set enableCulling to TRUE every time I change the text in for the TextMeshPro ?
The challenge with adding this as some property of the text object is because it is related to Culling which is material specific. As such this would affect all text objects that share this material.
When changing this property via scripting, an instance of the material is created and assigned to that specific text object. In the Editor / outside of play mode, we don’t want to be creating material instances. So the challenge in exposing this in the inspector is more resource management related. Maybe this should be exposed as a material property.
That is something I need to look into. As you pointed out the culling mode is only changed when this flag is set so if the text changes afterwards resulting in additional submesh objects being created, then these submesh objects won’t have that flag set correctly.
Until I make changes to properly handle this, you would have to check the culling setting is correct on those submesh objects.
What I will do is, in runtime if a new emoji is being added - then I will
GetComponentsInChildren<> for TMP_SubMesh. I will iterate the returned array to set enableCulling to TRUE on all of them.
In the Editor via the Inspector, this will automatically sync culling mode between the parent text object and sub objects.
In terms of Workflow, instead of setting this property via the text object “enableCulling” property, this should be set on the material now. Culling mode will mirror those of the parent text object.
I still need to address culling modes not getting automatically synced with the parent text object when using the “enableCulling” property and then adding a sprite or fallback but given culling can now more easily be controlled via the Material Inspector, I am not even sure I should continue to expose that property. Thoughts?
This new feature requires updating all TMP shaders and as such will require re-importing the TMP Essential Resources when this is available in the next release.
Thank you for your response. When you say added, should I just update the package manager? I am on Unity 2018.4.10f1 (LTS version)
As for suggestion is concerned, as you’re only exposing in debug mode - I would suggest that to be an API call.
But however, if a user does explicitly set the culling mode on a parent - it should comply to that boolean value for any or all of its children. Also when the user modifies the text(string) or any other properties on that TMP component, it should adhere to that boolean value till the end of its lifecycle.
This will be in the next release which will be version 1.5.0-preview.2 for 2018.4 and 2.1.0-preview.2 for 2019.x or newer. These new releases will be out this week.
It is not debug mode but in the Debug Settings section of the Material Inspector as seen below.
The Cull Mode of the parent text object will be automatically mirrored on the child sub text objects.
Since control over Culling is functionality specific to shaders and materials, I think it is more intuitive and easier for users to access this functionality via the Material Inspector. Furthermore, I believe in the vast majority of use cases, users would typically want to do this in the Editor / Scene Hierarchy as opposed to changing culling modes at runtime.
It is also important to note that culling modes are accessed via the material which in the end is how TMP handles this via this enableCulling property. As such, users can always access the material of the text object to control culling modes on that material.
// Sets the culling mode to "cullingMode" value on the shared material.
renderer.sharedMaterial.SetFloat(ShaderUtilities.ShaderTag_CullMode, cullingMode);
// Creates an instance of the material and sets the culling mode to "cullingMode" value.
renderer.material.SetFloat(ShaderUtilities.ShaderTag_CullMode, cullingMode);
P.S. I won’t remove this enableCulling property from the API since users are already using it.
If I am correct → You’re trying to change the cullmode property from a script. If that is the case please check the property “_CullMode”. I think it should be just “CullMode”.
Here is the Important Note that I posted related to this in the following stick thread .
IMPORTANT NOTE:
As a result of adding support for setting culling mode in the material in the Debug Settings of the material inspector, users should update the TMP Essential Resources via the “Window - TextMeshPro - Import TMP Essential Resources” menu option to import the revised shaders.
There is also a minor fix available in this post for another potential issue related to this change.
Since the shaders rarely get edited unlike font assets and other TMP resources, I am exploring moving the shaders into the TMP package for the next release. This would ensure that future shaders changes do not require updating of the TMP Essential Resources.