I am getting this error from TMPro_Private.cs file. I can’t fix the file. Any ideas to work around?
Destroying components immediately is not permitted during physics trigger/contact, animation event callbacks, rendering callbacks or OnValidate. You must use Destroy instead.
UnityEngine.Object:smile:estroyImmediate(Object)
In previous versions of Unity, the Graphic class had [RequirementComponent(CanvasRenderer)] which would automatically add a CanvasRenderer to any class inheriting from it like the TMP_Text class. This resulted in a forcing a CanvasRenderer being add to normal objects which don’t need it.
In newer versions of Unity 2019.4, this was changes. As such, when TMP detects an unnecessary CanvasRenderer, it tries to remove it but I guess that can result in issues like you ran into.
The solution is to simply manually remove those unnecessary CanvasRenderers from those objects, prefabs, scenes and re-save them.
The CanvasRenderer should be removed so not sure about the MeshRenderer part.
In hindsight, I will revise this handling to issue a warning indicating that CanvasRenderer should be removed and make the CanvasRenderer visible to make it easy to remove. But I will not be removing it automatically.
In my case there was no Canvas Renderer.
Its the textmesh component over the Entity Object.
After the upgrade, I was getting the error on instantiating those Entity Objects.
After removing and adding these (TextMeshPro & MeshRenderer) components back, the errors stopped.
Much of this rework (I just had to recreate 10 different prefabs) could be moot if line 78 of TMPro_Private.cs read:
Destroy(canvasRenderer); instead of DestroyImmediate(canvasRenderer);
Of course, I tried doing this myself and it would last mere seconds as the package manager seemed to detect the change and revert it.
I have revised this handling where instead a warning will be issued to notify the user to remove the unnecessary CanvasRenderer from those objects and prefabs. The previously hidden CanvasRenderer will no longer be hidden to make it easier to remove from those objects / prefabs.
This change will be included in the next package release which I am hoping to have available sometime this week.