Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

TextShadow not working?

Discussion in 'UI Toolkit' started by PPE-TrackMan, Jul 6, 2021.

  1. PPE-TrackMan

    PPE-TrackMan

    Joined:
    May 4, 2021
    Posts:
    9
    Hi,
    I am trying to add some shadow to a large title text, both through code.
    e.g.
    Code (CSharp):
    1. var shadow = new TextShadow();
    2. Shadow.color = Color.blue; //And blur radius and offset.
    3. text.style.textShadow = new StyleTextShadow(shadow);
    and they do not get into the inline styles for the element.

    And even when modifying the values directly, then it doesn't get a shadow.
    upload_2021-7-6_14-7-50.png

    How should I debug this?

    Best regards Povl
     
  2. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    443
    Hi! Could you look at the alpha value of the color? What's strange to me is that you set a shadow color of blue, and it appears red in the debugger.
     
  3. PPE-TrackMan

    PPE-TrackMan

    Joined:
    May 4, 2021
    Posts:
    9
    The code was simplified and I just took the first color in the dropdown. Bad example, that is on me.

    upload_2021-7-7_9-1-10.png
    upload_2021-7-7_9-1-41.png
    Have tried with both extremes of alpha values and a middle ground.
    Offset and blur values of 1 to 1000.
    Still no shadow =(
     

    Attached Files:

  4. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    443
    Thanks! A few other questions, which version of UI Toolkit and which font are you using?

    I believe there is a bug in com.unity.ui-preview.14 where you have to use a FontAsset for the text-shadow to work. It is fixed in 2021.2 and will be in preview.15.

    Also, have you tested text-shadow in the UI Builder?
     
  5. PPE-TrackMan

    PPE-TrackMan

    Joined:
    May 4, 2021
    Posts:
    9
    Current version:
    upload_2021-7-7_16-0-18.png
    It does work in the UI Builder, when adding the font asset.

    We are using a custom tool to generate the uxml from a design tool, so we cannot go directly in and using the builder.
    Can that Font Asset be easily set from code?
    and when is preview 15 planned for release?

    We have a work around, with creating two text fields and handling the offset manually, however this would be better =)
     
  6. HugoBD-Unity

    HugoBD-Unity

    Unity Technologies

    Joined:
    May 14, 2018
    Posts:
    443
    Yes, there is indeed a bug in preview.14. You'll first need to create a FontAsset from the Font you are currently using. (right-click the Font -> Create/Text/Font Asset) You'll then need to assign the FontAsset through the -unity-font-definition style property. Here's a post that explains it with more details:

    https://forum.unity.com/threads/feedback-wanted-new-text-engine.1007585/

    I hope that helps!