- Home /
TextMeshPro meterial reverts to preefab default after collision
Hi, I have a gameobject within it there is a TextMeshPro gameobject. I used to change the material of TMP in awake() to customize it according to some criteria(worked fine 100%). Recently after an issue with unity I exported all stuff as pkgs then imported them one by one to a new project overall works fine except new feature. I realised that the this gameobject plays always its animation with the default material.
ChokoPiece.GetChild(0).GetChild(2).gameObject.GetComponent<MeshRenderer>().material = GetTextMat(index);
this code works fine I can check it and it changes the material but when the collision happen the TMP material reverts to the default one in the prefab and play animation after!!??.
one thing I noticed is that if I leave the TNP active = true animation plays with correct material. I tried keep it active then set it to inactive in script after setUp(same issue)
Can anyone direct me where is the problem plz? I tried using renderer material/sharedMaterial, meshrenderer material/sharedMaterial, and TMP material property no luck. It updates in awake method then reverts to default in OntriggerEnter event handle
Answer by Keita-kun · Jul 18, 2021 at 03:23 AM
Here is My solution after some research, I found a TMP ugui issue that pointed out to my solution. in Unity 2019.4.20 and earlier I was using gameObject.GetComponent<Renderer>().sharedMaterial or material
, it seems I have to use now gameObject.GetComponent<TextMeshPro>().fontMaterial
even with the TMP object deactivated. the updated material is used as it was before. same issue applies for Unity 2019.4.28 I wonder if it is an updated way of doing thing?
Your answer
Follow this Question
Related Questions
HELP with scripting where GUI is involved 2 Answers
Material doesn't have a color property '_Color' 4 Answers
Bitmap text blurry 1 Answer
Text displays during animation 1 Answer