docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method RefreshString

    RefreshString()

    Forces the string to be regenerated, such as when the string formatting argument values have changed.

    Declaration
    public void RefreshString()
    Examples

    This example shows how to refresh the string when the value of a variable has changed.

    public class RefreshStringExample : MonoBehaviour
    {
        // Set via inspector
        public LocalizeStringEvent localizeStringEvent;
    
        // Set via code
        [HideInInspector]
        public int someValue;
    
        void Start()
        {
            // Assuming the localized string is in the format "The value is {someValue}"
            localizeStringEvent.StringReference.Arguments = new object[] { this };
    
            // Add a listener to the event
            localizeStringEvent.OnUpdateString.AddListener(OnStringChanged);
        }
    
        void OnStringChanged(string s)
        {
            Debug.Log($"String changed to `{s}`");
        }
    
        public void SetValue(int value)
        {
            someValue = value;
    
            // The localized string does not know the value has changed so we call RefreshString to force an update.
            localizeStringEvent.RefreshString();
        }
    }
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)