My Unity scene has multiple objects containing a TextMeshPro component which I want to programmatically change in the Editor using the code below. The script runs successfully when i attach it to an object in the scene, though each of these changed font sizes revert back (to the value before the script executed) after starting the scene in Play Mode.
Initial font size = 0.06 -> attach script to an object, automatically runs OnValidate -> new font size = 0.04 -> Remove script from object, font size remains 0.04 -> Start Play Mode -> font size reverts to 0.06 -> Exit Play Mode -> font size = 0.06
Manually changing the font sizes maintains the new values even during the Play Mode (so no reversion). What could cause the font size persistence issue when utilizing the script?
[ExecuteInEditMode]
public class ChangeAllFonts : MonoBehaviour
{
void OnValidate()
{
TextMeshPro[] textMeshPro_Objects = Object.FindObjectsOfType<TextMeshPro>();
foreach (TextMeshPro textMeshPro_Object in textMeshPro_Objects)
{
textMeshPro_Object.fontSize = 0.04f;
}
}
}