Colour Outline, Not Changing via Script, Issue

Hi there,
Ive been using TMP in my project and I love it, for the most part.

In regards to changing colours, of a TMP unit, material, outline or face, I am aware this will effect all other instances that share this material. This is fine, however, in code, when I run the program, the color seems to not change as it should.

Can there be any reason for a material color (outline) for example, not change to the color I set it to, in script, if I have altered it, but hand, in the editor, before run?

Thanks.

The outlineColor property is of type so make sure that you setting and using Color32.

Also be mindful that properties like outlineColor create an instance of the material. Internally, this colorOutline is simply accessing one of the material properties.

Thanks for the quick response.

  • I changed the variable from Color to Color32 but the same issue occurs.
  • I deleted and regenerated the object but the same issue occurs (that has worked in the past)
  • this project has been fine for weeks, and this issue just popped up today.

Please let me know of anything we can do to sort this out.

Thank you!

This should all be working. What values are you using to set this Color32?

Also be mindful that the outline itself like underlay uses a shaderkeyword. So perhaps the material that you are using doesn't have those shaderkeywords enabled to begin with.

While on this topic. Any reason why you are setting the outline color via script instead of using a pre-defined Material Preset? Do you have several text objects all with different outline colors?

Hi thanks,
Ive included screenshots of the material setting.

I am using script for the following reasons.

  • I have 6 worlds, each has their own font color arrangement (face and outline).
  • I use the same scene, gameplay, levels selection, world selection, regardless of which world is open. The objects within, including TMP entities, are instructed to adjust their face and outline colours accordingly.

I can't see from the image where the issue might be. I suspect it is related to how this outline color is being set via scripting.

Any chance you could share with me a simple repro which you can provide via private link in a PM or simply by submitting a bug report with Unity and providing me with the case #.

While we figure out the issue together. Here is another suggestion: If you are only using an Outline with or without Underlay, I would switch the shader to use the Mobile Distance Field version which is a bit more efficient than the full distance field that you are using right now.

In terms of handling of the materials, I would still learn towards using Material Presets which are pre-define for each of those worlds and then assign those material instead of modifying the materials via scripting.

If modifying those outline via scripting ends up being the best option, I would make sure that I only create one material instance with a given outline and color for each group of text objects. Ie. modifying the outline over several objects results in several instance of essentially the same material which results in several extra draw calls. Whereas at least re-using the same material instance on several text object would be more efficient in terms of draw calls.

Just for testing...

Create a new text object of type and add the following script to it. Make sure the text object has a material that is using the normal Distance Field shader and not the Mobile Distance Field since this script doesn't enable the outline keyword.

using UnityEngine;
using System.Collections;
using TMPro;

public class SandBox_08 : MonoBehaviour
{
    private TMP_Text m_TextComponent;

    void Awake()
    {
        m_TextComponent = GetComponent<TMP_Text>();
        m_TextComponent.text = "A line of text.";
        m_TextComponent.color = Color.yellow;
        m_TextComponent.outlineWidth = 0.15f;
        m_TextComponent.outlineColor = Color.red;
    }
}
1 Like

@Stephan-B

This is how I am setting the colours...

Font_Color_Holder.ins is an object that exists in each level. This script, function exists on each font object. It manages 2 objects (each has a Text Mesh Pro (Script)). It gathers the colours, from the Font Color Holder and sets them as such....

    void set_colors(){
        Color c_face = Font_Color_Holder.ins.c_face [LoadingMng.int_world];
        Color32 c_outline = Font_Color_Holder.ins.c_outline32 [LoadingMng.int_world];
        units [0].faceColor = c_face;
        units [0].outlineColor = c_outline;
        units [1].faceColor = c_outline;
        units [1].outlineColor = c_outline;

        print ("OUTLINE COLOR " + c_outline);

    }

-.... again this has been working fine for months, until this afternoon. (Of course the day before release! So yes, it is urgent, so I thank you for the support.).

  • Mobile Distance Field did not work.

  • as for only creating one material per color arrangement, I had chosen this method (shared) to save memory. To create one per arrangement, means at least 12 objects, not too bad on memory I guess.

So odd as this had been working, like I say.

  • I ran your test, seems to work just fine!

What is the value of that c_outline color?

Given it is a Color32, each color component should be a byte of value 0 to 255.

Do you assign a new material to these text objects? Do you assign these new colors just after changing the material?

What might have changed since the last time you tested this? Did you upgrade Unity? Did you change materials? Any change to those scripts?


Not between 0 and 1?

The print shows (0, 73, 246, 255). This should be a strong blue, I believe.

Is the faceColor changing?

Do you get the same behavior if you use a different material like any of the materials included with TMP?

Edit - When you ran the test above, did you try using your materials to see if the behavior is the same?

Y

Yes. The face seems to change fine.

If you look, you see here two tone manipulation....

The background colour is purple....
then there are two text Mesh Pro units in front. One is slightly below and behind in position, to give to two objects (with the same string) a visual depth.

As you can see the outline is not in effect.

??

Do you get the same behavior using any of the font assets included with TextMesh Pro? Make sure you enable Outline (in the material inspector) or switch the shader to the full Distance Field version.

1 Like

Hi...
I think I was mistaken.... same effect no matter the material.

What I see is, in the scene window, is the font turn yellow, with a red outline, however the outline is a rough shape or the character. It is not tight fitting to the font.

This same outline can't be seen in the Game View.

... I think at this point, it may be best to jay create a separate material for each color.

Unfortunate tho, as it was working!!!

Anyhow, thank you for your help and the asset!!!

If this was working, it must be something trivial that is being overlooked. You can always quickly submit a Unity bug report and include the project. This way I can take a look at it and hopefully quickly spot what is causing this behavior.

1 Like

If I had to bet, it will be gone in the morning.
Cheers!

You know where to find me if you need further assistance.

1 Like


So I found it!!!!!
The Material, Outline, was not enabled.
Done.

1 Like

Sorry about the necropost, but this is definitely still an issue in TextMesh Pro version 1.3.0
Trying to change outline colour only works the first time in my project, but I figured out that I could work around this limitation by directly accessing the shared font material and toggling the gameobject on/off to force it to update:

_text.gameObject.SetActive(false);
_text.fontSharedMaterial.SetColor("_OutlineColor", outline);
_text.gameObject.SetActive(true);
3 Likes