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.

Can't remove CanvasRenderer because TextMeshPro (Script)....

Discussion in 'UGUI & TextMesh Pro' started by petera1980, Jun 26, 2020.

  1. petera1980

    petera1980

    Joined:
    Jan 29, 2016
    Posts:
    51
    Hello,

    I get this error every time Unity reloads.

    Can't remove CanvasRenderer because TextMeshPro (Script), TextMeshPro (Script), TextMeshPro (Script) depends on it

    After I open TMPro_Private.cs and remove this code on line 89

    Code (CSharp):
    1. CanvasRenderer canvasRenderer = GetComponent<CanvasRenderer>();
    2.             if (canvasRenderer != null)
    3.             {
    4.                 Debug.Log("Removing unnecessary CanvasRenderer component from text object.", this);
    5.                 DestroyImmediate(canvasRenderer);
    6. }
    7.  
    8.  
    Why script try to remove Canvas if TextMeshPro need it ?

    And after restart unity move fresh copy of this file and I have to remove code again.

    Please help.
     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    The CanvasRenderer in Unity 2019.x and prior is added automatically by the Graphic.cs class part of the UI / Canvas system.

    In a later version of 2019.x, the requirement was removed where the normal TMP component will no longer have a CanvasRenderer.

    Although a CanvasRenderer is added, it doesn't do anything nor do it impact performance. It is just there and annoying.
     
  3. petera1980

    petera1980

    Joined:
    Jan 29, 2016
    Posts:
    51
    Thank you Stephan. The only problem is that I have to remove code that checks for Canvas on textMesh because it throws an exception.

    Ok I will wait for next release.
     
  4. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    Actually what version of Unity and TMP are you using?

    Contrary to my previous message, the removal of the CanvasRenderer component is in version 3.0.x of the TMP package which is for Unity 2020.x.
     
  5. petera1980

    petera1980

    Joined:
    Jan 29, 2016
    Posts:
    51
    I use 3.0.0 preview version. It is annoying every Unity restart to edit TMPro_Private.cs and remove canvasRenderer != null condition.
    Please fix it in future versions.

    Thank you
     
  6. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    What version of Unity are you using?

    You should not have to be editing anything, I suspect you might be using a version of Unity that predates the changes to remove the CanvasRenderer requirements.
     
  7. petera1980

    petera1980

    Joined:
    Jan 29, 2016
    Posts:
    51


    I'm using Unity 2019.40f1

    I have attached screenshot from my Editor.
     

    Attached Files:

  8. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    With Unity 2019.x, you have to be using version 2.1.0-preview.x where the latest is Preview 14.

    Version 3.0.0-preview.x is for Unity 2020.x.
     
    multimediamarkers likes this.
  9. petera1980

    petera1980

    Joined:
    Jan 29, 2016
    Posts:
    51
    A ok I got it. Thank you for help.
     
  10. tyoungjr

    tyoungjr

    Joined:
    Nov 15, 2013
    Posts:
    5
    Yes, what fixed it for me was going into the manifest.json and packages-lock.json and changing textmesh pro to use version 2.0.1 upload_2020-7-24_15-17-26.png
     

    Attached Files:

  11. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    What version of Unity are you using?

    What version of the TMP package were you using?
     
  12. gnovos

    gnovos

    Joined:
    Apr 29, 2020
    Posts:
    10
    I have the exact same issue. As far as I know, I'm on 2020.1.0f1. I upgrade from some LTS build which I can't remember. I get the above message every time I instantiate a prefab button that has a TMP on it, i.e.:

    Removing unnecessary CanvasRenderer component from text object.
    UnityEngine.Debug:Log(Object, Object)
    TMPro.TextMeshPro:Awake() (at Library/PackageCache/com.unity.textmeshpro@3.0.0-preview.1/Scripts/Runtime/TMPro_Private.cs:88)

    and

    Destroying components immediately is not permitted during physics trigger/contact, animation event callbacks, rendering callbacks or OnValidate. You must use Destroy instead.
    UnityEngine.Object:DestroyImmediate(Object)
    TMPro.TextMeshPro:Awake() (at Library/PackageCache/com.unity.textmeshpro@3.0.0-preview.1/Scripts/Runtime/TMPro_Private.cs:89)
    UnityEngine.Object:Instantiate(GameObject)
    ResourceLoader:spawn(String) (at Assets/Scripts/ResourceLoader.cs:53)


    (p.s. I have no other information about this unless you can direct me where to look)
     
    Last edited: Jul 28, 2020
  13. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    In previous versions of Unity (2019.3.x) the Graphic class contained [RequireComponent(typeof(CanvasRenderer))] as such, any normal <TextMeshPro> object working with the MeshRenderer would still get a CanvasRenderer added to it which was unnecessary but could not be removed due to the above required component.

    In a later release of 2019.3, this requirement was removed thus no longer forcing a CanvasRenderer on normal <TextMeshPro> components.

    However, any scene containing text objects or prefabs created prior to this change ended up with a CanvasRenderer added to those objects which TMP now tried to remove in Awake as it is no longer necessary.

    In order to resolve this / suppress this message, you should update those scenes / prefabs that contain <TextMeshPro> objects to remove the CanvasRenderer component.

    Note: The CanvasRenderer component is still required for <TextMeshProUGUI> text objects but not for the <TextMeshPro> objects.

    Let me know if you run into any other issue performing the above task.

    I would also suggest updating to version 3.0.1 of the TMP package which was released yesterday and will become the verified release of TMP for 2020.x.
     
    ow3n likes this.
  14. petera1980

    petera1980

    Joined:
    Jan 29, 2016
    Posts:
    51
    I have have installed v2.0.1 for 2019.4.5f1 and problem is done.
     
  15. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    The message is gone but all normal TextMeshPro objects will still have a CanvasRenderer that although inactive is no longer needed on those objects.

    This message is only displayed when using the newer versions of the TMP package because your normal <TextMeshPro> object were created in a prior version of Unity where a CanvasRenderer was forced on all text objects.

    The solution as per my previous post is to simply remove the Canvas Renderer component from those game objects in scenes and prefabs that contain <TextMeshPro> components.
     
    Last edited: Jul 28, 2020
    ow3n likes this.
  16. petera1980

    petera1980

    Joined:
    Jan 29, 2016
    Posts:
    51
    Stephan_B, In the beginning I tied to remove Canvas Renderer as the first step of troubleshooting but I couldn't do that because then error "Component Canvas Renderer required by Textmesh" throw up.
     
  17. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    First, you must be using Unity 2019.4.x. This is when the requirement was removed for the CanvasRenderer in the Graphic class.

    Second, you must also be using TMP version 2.1.x where the requirement for the CanvasRenderer was also changed.
     
  18. petera1980

    petera1980

    Joined:
    Jan 29, 2016
    Posts:
    51
    Yes I'm using Unity 2019.4.x with TMP 2.1.
    Error gone after I removed TMP 3.x and installed 2.1.x
     
  19. tyoungjr

    tyoungjr

    Joined:
    Nov 15, 2013
    Posts:
    5
    3.0.0- This is the version the CreatorKit2D RPG was using in manifest.json before downgrading.
     
  20. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    As I have explained in this post above, as long as you are using the latest version of Unity 2019.4 along with TMP package version 2.1.1 everything should work fine.

    You will still get a message in the console when loading a scene or prefab that contains a game object that contains a <TextMeshPro> component and CanvasRenderer which again is no longer necessary to have on that game object. Manually removing this CanvasRenderer component and re-saving the scene or prefab will result in this message no longer being issues.
     
  21. jlango

    jlango

    Joined:
    May 17, 2013
    Posts:
    1
    I'm using Unity 2020.1.6f1 with TextMeshPro 3.0.1

    My TextMeshPro prefabs do not have CanvasRenderer components, they only have a MeshRenderer component. So there is no CanvasRenderer to remove. I'm still getting the following message logged for every instantiation (clogging up my console).

    Removing unnecessary CanvasRenderer component from text object.
    UnityEngine.Debug:Log(Object, Object)
    TMPro.TextMeshPro:Awake() (at Library/PackageCache/com.unity.textmeshpro@3.0.1/Scripts/Runtime/TMPro_Private.cs:77)
     
  22. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    The CanvasRenderer is hidden on normal <TextMeshPro> objects. When those objects / prefabs are loaded and a CanvasRenderer is present and as per this message, it removed.

    In order to avoid seeing this message again, just re-save the scene or prefab and the message will no longer appear.

    To avoid this confusion, in the next release of TMP, the CanvasRenderer will be made visible but not removed with a revised message about recommending remove it manually from those objects / prefabs.
     
  23. Saturn1004

    Saturn1004

    Joined:
    Nov 14, 2014
    Posts:
    41
    I just upgraded from 2020.1 to 2020.2 and started getting the same error about removing unable to remove CanvasRenderer because a TextMeshProUGUI component depends on it... 6 errors every time a scene is opened. But the errors are unclickable so tracking which object is throwing them would be impossible.
    I tried opening the scene and re-saving it but that did nothing.
    I tried opening every prefab with TextMeshProUGUI objects and re-saving them and that did nothing.
    Since they are harmless but annoying I guess I just have to ignore them?
    Edit: For some reason they prevent me from building the project... so not harmless after all.
    The only other version of Text Mesh Pro available (3.0.1) also does the same thing... so Unity 2020.2 is completely unusable for me because of this error.
     
    Last edited: Dec 20, 2020
  24. shelllee

    shelllee

    Joined:
    Apr 12, 2018
    Posts:
    11
    Code (CSharp):
    1.  
    2.         public CanvasRenderer canvasRenderer
    3.         {
    4.             get
    5.             {
    6.                 if ((object)m_CanvasRenderer == null)
    7.                 {
    8.                     m_CanvasRenderer = GetComponent<CanvasRenderer>();
    9.                     if ((object)m_CanvasRenderer == null)
    10.                     {
    11.                         m_CanvasRenderer = base.gameObject.AddComponent<CanvasRenderer>();
    12.                     }
    13.                 }
    14.  
    15.                 return m_CanvasRenderer;
    16.             }
    17.         }
    The canvasRenderer cannot add CanvasRenderer Component successfully when
    graphic.canvasRenderer == "null"
    .
     
  25. damelin

    damelin

    Joined:
    Jul 3, 2012
    Posts:
    49
    Hello, I have upgraded my project from 2019 to 2020.3.18, and using TMP package v3.0.6.

    I'm seeing this warning:

    Please remove the CanvasRenderer component from the [Label] GameObject as this component is no longer necessary.
    UnityEngine.Debug:LogWarning (object,UnityEngine.Object)
    TMPro.TextMeshPro:Awake () (at Library/PackageCache/com.unity.textmeshpro@3.0.6/Scripts/Runtime/TMPro_Private.cs:121)


    The prefab has a TextMeshProUGUI component which contains a [RequireComponent(typeof(CanvasRenderer))]
     
  26. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,581
    The warning is coming from a <TextMeshPro> component as per the above log entry.

    This indicates this object contains a normal <TextMeshPro> component which is the one that no longer needs to have a CanvasRenderer on this object.

    You should be able to click on the warning message and it should ping / select the relevant object so you can remove this component from it.

    .
     
    damelin likes this.
  27. BasicallyGames

    BasicallyGames

    Joined:
    Aug 31, 2018
    Posts:
    86
    I'm so confused. I'm using Unity 2020.3.34f1 and TextMeshPro 3.0.6. When I try to remove the canvas renderer from TextMeshPro objects, it won't let me, it says TextMeshPro relies on it. Not only that, but when I create a new TextMeshPro object, it is created with a canvas renderer. I'm not seeing the behavior Stephan is describing.

    Edit: Okay, just realized what's going on. The warning was coming from TextMeshes not attached to a canvas. I was assuming the error and the info in this thread was referring to TMPs on canvases, hence the confusion.
     
    Last edited: May 7, 2022
  28. Patroclo

    Patroclo

    Joined:
    Jan 14, 2016
    Posts:
    5
    Unity version: 2020.3.38
    TMP version: 3.0.6

    I am having the following warning:
    Please remove the CanvasRenderer component from the [TextMeshPro] GameObject as this component is no longer necessary.


    If I remove the CanvasRenderer. I stop having the warning, and I start to have an error that says:
    MissingComponentException: There is no 'CanvasRenderer' attached to the "TextMeshPro" game object, but a script is trying to access it.


    I tried to import the essential resources and the error continues.