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. Join us on March 30, 2023, between 5 am & 1 pm EST, in the Performance Profiling Dev Blitz Day 2023 - Q&A forum and Discord where you can connect with our teams behind the Memory and CPU Profilers.
    Dismiss Notice

TextMesh Pro Removing unnecessary CanvasRenderer component from text object. (without CanvasRender ?)

Discussion in 'UGUI & TextMesh Pro' started by BLxSug, Sep 1, 2020.

  1. BLxSug

    BLxSug

    Joined:
    Sep 13, 2019
    Posts:
    5
    Hello,
    I get this error every time Unity enter in "play".

    Removing unnecessary CanvasRenderer component from text object.

    (Incrimining the same script in this post.)

    So, I inspected my prefab (from which it came) and can see no CanvasRederer, there is only :
    -RectTransform
    -MeshRenderer
    -TextMeshPro - Text

    Code (CSharp):
    1. // Remove CanvasRenderer from text object if one exists
    2.             CanvasRenderer canvasRenderer = GetComponent<CanvasRenderer>();
    3.             if (canvasRenderer != null)
    4.             {
    5.                 Debug.Log("Removing unnecessary CanvasRenderer component from text object.", this);
    6.                 DestroyImmediate(canvasRenderer);
    7.             }
    So I don't understand why this log is called.

    I'm using Unity 2020.1.3f1
    with TextMeshPro 3.0.1

    Thank you in advance !
     
    Last edited: Sep 1, 2020
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,326
    If this is the whole code that deletes the CanvasRenderer, then it's missing to mark the object/scene as dirty. Meaning, Unity doesn't know of the change, thus not saving it, thus doing the same work every time you reopen the scene.

    You should call
    UnityEditor.EditorUtility.SetDirty(gameObject);
    after deleting the canvasRenderer.
    https://docs.unity3d.com/ScriptReference/EditorUtility.SetDirty.html

    Another workaround could be to open the scene, Unity deletes the canvasRenderer. You add a new GameObject to the scene, delete the new gameobject again and then save the scene.
     
  3. BLxSug

    BLxSug

    Joined:
    Sep 13, 2019
    Posts:
    5
    Sorry, I misspoke, I mean : I get this error every time Unity enter in "play".
    And this code is from ...\Library\PackageCache\com.unity.textmeshpro@3.0.1\Scripts\Runtime\TMPro_Private.cs
    this is not my code (and when I try to edit, it is regenerated)
    More, the object which trig this code are Prefab and generated on Awakening. (and have no CanvasRenderer on them...)
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    I have revised this handling to simply issue a warning now about the CanvasRenderer no longer being necessary on <TextMeshPro> components and objects.

    This will require users to manually remove the CanvasRenderer component from those objects / scenes / prefabs and to then re-save those.

    This change will be in the next release of the TMP package.

    Until this new release is available, if you open any existing scene or prefab, you should get a message that the CanvasRenderer has been removed. If you save the scene or prefab, after the CanvasRenderer has been removed, you should no longer get this message.
     
  5. BLxSug

    BLxSug

    Joined:
    Sep 13, 2019
    Posts:
    5
    Thanks you, the important part was "re-save" the prefab ! (even if the CanvasRenderer was already deleted from the prefab...)
    Maybe when I opened prefab the CanvasRenderer was automatically delete on "live", so I couldn't notice it was still here...
    Well, anyway, problem solve !
    Thanks you !
     
    xVergilx and Stephan_B like this.
  6. axmsw

    axmsw

    Joined:
    Mar 13, 2019
    Posts:
    4
    I couldn't see the CanvasRenderer on the TMP objects in the prefab, so couldn't delete it. But the messages were still turning up in Debug log. So I added the CanvasRenderer to one of the TMP objects then removed it, and it seemed to work.
     
  7. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    2,960
    The issue is that .Awake is called in editor as well, resulting in a CanvasRenderer being deleted.
    But prefab is never marked as dirty, and a result - it cannot be re-saved.

    If anyone encounters this - just tweak any property of the prefab, and then save it. This error should go away.

    Also, @Stephan_B from the code perspective - please move this component removal to editor time.
    (E.g. OnValidate + delayed removal should do the trick)

    This should save up some extra ticks from check and GetComponent.
     
    Last edited: Oct 7, 2020
  8. ExcaliburGames

    ExcaliburGames

    Joined:
    Oct 29, 2013
    Posts:
    49
    Thank you! Works for me.
     
  9. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,304
    I'm getting this warning a lot in TextMesh Pro 2.1.3 / 3.0.3, which seems fine. Unfortunately, when I try to remove the CanvasRenderer, Unity pops up a strange warning:

    upload_2020-12-26_16-31-1.png
    One possible issue might be that I'm using TextMesh Pro 3.0.3 with Unity 2019.4 (there was one compilation error that I had to fix but I don't know if there are any other differences between 2.1.3 that might cause trouble in 2019.4).

    I've had a look at TextMeshPro.cs, and it looks all good (does require MeshRenderer but not CanvasRenderer). There is also TextMeshProUGUI which would require CanvasRenderer but I have double checked that this isn't used on that component.

    Any ideas what might be causing this?

    EDIT: Ok, apparently, this is a Unity version issue - I'm now using the 2.1.3 version of TextMesh Pro and on that version, I'm not getting any of those warnings. So maybe in Unity 2019.4, the CanvasRenderer is still necessary ...
     
    Last edited: Dec 26, 2020
  10. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    That is indeed the issue. In 2019.4 and prior Unity releases, a CanvasRenderer was automatically added by the Graphic class as a result of the [RequiredComponent] attribute where even the normal <TextMeshPro> component which uses the MeshRenderer was forced to have a CanvasRenderer.

    This requirement was eventually changed in 2020 which is one of the reasons why we have a separate version of the TMP package (3.0.3) for Unity 2020 or newer.
     
    jashan likes this.
  11. quitebuttery

    quitebuttery

    Joined:
    Mar 12, 2011
    Posts:
    313
    So the problem here is I have no idea what prefab it's talking about. I have hundreds (400+) of these messages in my log, but it doesn't say what the object is. Just "(object, UnityEngine.Object)" -- how can I find out which TMP objects have this canvas renderer so I can remove them?
     
  12. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    You should be able to click on each debug line and it should ping the relevant object in the project window.
     
  13. quitebuttery

    quitebuttery

    Joined:
    Mar 12, 2011
    Posts:
    313
    That doesn't happen. When I click on the debug line nothing happens. Maybe because the tmpro elements are sub objects on prefabs and you can't go that deep in a prefab in the project window?
     
  14. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    I guess it only pings those objects / prefabs when they are in a scene or if you end up selecting it.

    This warning only occurs in the Editor and as such is just informative to let you know that you can / should remove the CanvasRenderer from those game object and prefabs.

    I did modify the message to add the name of the game object which should make it a bit easier to hunt those down.

    You can make the same modification in the Awake() of the TMPro_Private.cs as seen below,

    upload_2021-1-24_17-15-0.png

    To make the change persistent, you will need to make it in the Global Package Cache.
     
  15. quitebuttery

    quitebuttery

    Joined:
    Mar 12, 2011
    Posts:
    313
    How do you make this modification? Every time I do, it gets overwritten with the original version.
     
  16. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    To make the change persistent, you will need to make it in the Global Package Cache.
     
  17. quitebuttery

    quitebuttery

    Joined:
    Mar 12, 2011
    Posts:
    313
    Aha! Interesting, this change also made it so when I click on the object it shows it in the scene. Fantastic.
     
  18. jashan

    jashan

    Joined:
    Mar 9, 2007
    Posts:
    3,304
    If you want proper version control, there's an (unofficial) mirror of Unity's packages that you can hook your version control up with: https://github.com/needle-mirror/com.unity.textmeshpro

    That way, you can apply your changes and still conveniently update the packages as needed (also, you can always conveniently check what changes you have applied). Using the Global Package Cache, your changes will almost certainly disappear as soon as you update the package the next time.

    I find it extremely unfortunate that Unity only has a few of their official packages on open GitHub projects.
     
  19. DEEnvironment

    DEEnvironment

    Joined:
    Dec 30, 2018
    Posts:
    428
    In Unity 2018.4 TextmeshPro verified version is 1.4.1 as prompted by unity installer for users

    as major assets in the Unity asset store support all pipelines and unity asset store have min build version requirements that must be strictly followed for uploads this change in textmeshpro has effectively removed are ability to use this wonderful tool

    the suggested fix by one time opening and removing the component will not work for assets that have min build versions in that the new textmesh versions are not rolled back into lower versions

    please give a solution that can be applied to permit continued featuring and support of texmeshpro
     
  20. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,588
    Version 1.5.6 is the latest verified version of TMP for Unity 2018.4. I strongly suggest that any users creating a new project in 2018.4 instantly update to version 1.5.6 of the TMP package as version 1.4.1 is pretty old now.

    I have been trying to update the Editor manifest to version 1.5.x but I keep running into internal build system / test framework issues that are only present on this internal system at Unity which are giving headaches and have been preventing me from doing so. I will keep trying but given there are only a few updates left of 2018.4, I may not be able to do so.
     
    DEEnvironment likes this.
  21. DEEnvironment

    DEEnvironment

    Joined:
    Dec 30, 2018
    Posts:
    428

    follow up
    as LTS 2018 has now ended the problem solved its self
    hope to bring TM back into our 2019.4 workflow soon :)

    cheers
    keep up the hard work thank you
     
  22. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    211
    Wouldn't it be nice if Unity offered to automatically remove all those CanvasRenderer components?

    I understand it's not a trivial operation because of prefabs (you have to remove components from the actual prefabs when you're dealing with a prefab instance), but we could have a script that searches through prefabs to remove the component, then through the scene to remove remaining components. Maybe add a warning that Unity will modify prefabs and scenes but generally it should do the right thing.

    For now I did that work manually, searching for all matching objects by filtering Hierarchy with "TextMeshPro" (for some reason "TextMeshProUGui" doesn't find all instances), then looking at object name color (white or blue) to identify prefab instances vs other objects.
     
    Robdon likes this.