Sync UI Text changes to all players

Hi, I have a world with UI text that can be updated via a UI InputField.
Currently only the player who changed the text see it updated.
I wish this text changes to be visible for all players in room.
Is that possible ?
I read about Network or Sync gameobject…
Many thanks in advance.

I’m on SDK3 and Unity 2019.4.31f1.

While looking for a solution I found that I probably need to use the Udon Networking features and sync a variable (string type ?) when my UI text is changed.
I guess I have to put the udon behaviour on the UI text gameobject (TextMeshPro) ?

Does someone could help with an example or a tutorial link ?
I’m a real noob in Udon graph !

So, VRC networking 1.0.1:

Almost everything is client side, until you tell the client to start syncing stuff with other users.
For my world “know your friends in space” I wanted to make it so the board game syncs the text that’s on the board with other players.

To achieve this, you’ll need 3 things.

  1. A parameter that you’ll synchronize. (This’ll be a string in your case)
  2. A parameter to indicate the local un-synced state of the object. After all, if it’s not out of sync, we don’t need to start an update routine.
    and lastly
  3. A routine to tell the users to re-sync with the master.

for U# it’d look something like this:

    public string syncedText;       //The string we'll be syncing across the network
    private string internalState;   //The internal state of our object
    public InputField inputField;   //The UI field we want to update.

    public void FixedUpdate()       //Fixed updates are run at a fixed moment, so they're not affected by lag.
        if(internalState != syncedText) //Check if our internal state matches the same state the master is at. if not update.
            internalState = syncedText;
            inputField.text = syncedText;
            RequestSerialization();     //We were out of sync with the master. It might be a good idea to tell everyone else to check themselves if they were out of sync.

    //This is called from the input field itself to indicate it updated. Sync this across the network.
    public void OnValueChanged()
        syncedText = inputField.text;
        RequestSerialization();         //Tell other players the text updated.

    //Some one joined, let's go ahead and make it so they get to see the updated text.
    public override void OnPlayerJoined(VRCPlayerApi player)

In terms of udon graph it’d be something like this:


1 Like

Thanks a lot @Luna_Delrey it looks very near of what I want :+1:
If I understood well this would update the InputField for everyone.

My situation is slightly different, I have an InputField that updates a Text area (TextMeshPro Text) and I just want the Text area to sync across players, not the InputField.

Then I guess I’d have to attach the UdonBehaviour to the Text area object and adapt the Udon Graph to something like this:

Am I right ?
Not sure about the “Get name”, why not “Get text” ?

I would prefer to use C# but did not manage to have it running without errors, do I have to use the code you gave just as it is or in a class ?

Thanks again for your help, I really appreciate :wink:

That’s because you have the wrong text mesh pro object. It’s TextMeshProGUI.text

As for using c# vrchat doesn’t allow for plain c# due to security issues. However it does allow for u#

Which is similar to c# but compiles into the udon aasembly and only allows the things that are within the bounds of udon.

You’ll also need to install udonsharp to use it:

And lastly, if you just want to update text you can just make the TextMeshProGUI variable public. Attach your script to an object, convert it to an udon behavior (there’ll be a button). And drag and drop the text onto the field in the inspector.

Great it’s working, thanks a million @Luna_Delrey !
I marked your previous post as the solution :+1: