Generic property in GameManager that applies to all components in scene

Hi, I have some options that will be applied to all objects with a certain component in the Scene.

For example, I have several text meshes in the scene and a font selector in GameManager. When that selector changes, all text meshes should change font in the scene view.

Right now I have a GameManagerEditor that will find all components in the scene and set the font (And the font material) but it doesn’t work. I have aswell a language selector and it should change the text of all text meshes, but it doesn’t work either.

#region Unity
    private void OnEnable( )
    {
        //--
    }

    public override void OnInspectorGUI( )
    {
        EditorGUI.BeginChangeCheck( );

        DrawDefaultInspector( );

        if( !Application.isPlaying && EditorGUI.EndChangeCheck( ) )
        {
            _ChangeTexts( );
            _ChangeTextFonts( );
        }
    }

    #endregion Unity

    private void _ChangeTexts( )
    {
        LocalizableText[] all_texts = Resources.FindObjectsOfTypeAll<LocalizableText>( );
        foreach( LocalizableText text in all_texts )
        {
            text.SetText( text.key );
        }
    }

    private void _ChangeTextFonts( )
    {
        TaleText[] all_tale_texts = Object.FindObjectsOfType<TaleText>( );
        foreach( TaleText tale_text in all_tale_texts )
        {
            TextMesh tm = tale_text.GetComponent<TextMesh>( );
            MeshRenderer mr = tale_text.GetComponent<MeshRenderer>( );
            if( tm && mr )
            {
                if( !tale_text.overrideFontSelection && GameManager.HasInstance )
                {
                    tm.font = GameManager.Instance.font;
                    mr.sharedMaterial = tm.font.material;
                    tm.text = "changed";
                }
            }
        }
    }

Firstly, what am I doing wrong? Debugging I can see that the code does execute, and it iterates through the text. But something weird happens since, for example, the text of the meshes are empty while they should have text (If I go to the inspector I can see there is texts on them) which make me thik something is not ok.

Secondly, if there is a better way of doing this I would love to know.

Thanks!

Firstly, be aware that Resources.FindObjectsOfTypeAll will scan your prefab assets as well, and Object.FindObjectsOfType will return only active objects.

I’m working on a project with multi language support using events. I have a static settings class, something like

public static class Settings
{
    static public event Action<UILanguage> EventChangeLanguage;

    static UILanguage languageType = UILanguage.English;
    static public UILanguage LanguageType
    {
        get
        {
            return languageType;
        }

        set
        {
            if (languageType == value)
                return;

            EventChangeLanguage(language);
        }
    }  
}

and then a client behaviour attached to each Text UI Control (text, buttons, etc) listening this event

public class UIText
{
    protected virtual void OnEnable()
    {
        Settings.EventChangeLanguage += Settings_EventChangeLanguage;
    }

    protected virtual void OnDisable()
    {
        Settings.EventChangeLanguage -= Settings_EventChangeLanguage;
    }
  
    void Settings_EventChangeLanguage(UILanguage language)
    {
        // apply changes
    }
}

They never receive any direct text string, but language tokens (enum), mapped by translators into real text strings.

Problem here is that text won’t change unless you click it, right?