Search Unity

Resolved GameObject material reverts to prefab default at after script modification @ runtime

Discussion in 'Animation' started by Keita-kun, Apr 6, 2021.

  1. Keita-kun

    Keita-kun

    Joined:
    Aug 20, 2017
    Posts:
    36
    Hi everyone,
    I have a prefab that contains a TextMeshPro gameobject, the parent gameobject has a setup script that modifies the material of the TMPro child gameobject (script works fine). Actually when the OnTriggerEnter event occurs the TMPro gameobject is activated and animation plays with the default material on the TMPro gameobject.

    if I keep the the TMPro gameobject active(not suitable for the game) the animation plays as expected
    if keep it active during the setup then deactivate it same issue
    before upgrade 2019.4.21 the animation played correctly.
    Can anyone point me to where the issue/error is. I posted on answers site also https://answers.unity.com/questions/1827192/textmeshpro-meterial-reverts-to-preefab-default-af.html
     
    Last edited: Jul 18, 2021
  2. Keita-kun

    Keita-kun

    Joined:
    Aug 20, 2017
    Posts:
    36
    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
    Code (CSharp):
    1. gameObject.GetComponent<Renderer>().sharedMaterial
    , it seems I have to use now
    Code (CSharp):
    1. gameObject.GetComponent<TextMeshPro>().fontMaterial
    even with the TMP object deactivated. the updated material is used as it was before same applies for Unity 2019.4.28