The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on Fusion.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

[FUSION] Sync text between clients

Ritarirane
2022-07-02 12:44:01

Hey,

absolute photon noob here, how do i sync text between 2 clients?

here is my code:

my string:

[Networked] string networkedtext { get; set; }

my rpc:

[Rpc(RpcSources.All, RpcTargets.All)]

void RPC_SendMessage()

{

networkedtext = new System.Random().Next(1, 11).ToString();

TextField.text = networkedtext;

Debug.Log("RPC executed");

}

i call the rpc every 3 secs but clients have different numbers

RPC_SendMessage();

Comments

Isaac_Augusto
2022-07-04 09:57:59

Hi,

Please use the type [Networked] NetworkString<_x> networkedtext {get;set;} where x is the size of your string in memory.

e.g: NetworkString<_2>, NetworkString<_4> ...

I'm not sure if you're using Shared or Host/Server mode, but in either case you need to sent the RPC only to the State authority over the NetworkObject. , each client is getting a different number because each one is running the random function. So it should be something like that:

And you need to have a OnChanged for assig the text field, instead of the RPC, because the RPC will run only on the state authority now. Please take a look at the samples and documentations to understand better, but for now the networkedtext should be sync between the clients, you can Debug.log it on the FixedUpdateNetwork or the unity Update, but only use networked values for logic on the FixedUpdateNetwork.

Hope this was helpful.


Isaac Augusto

Photon Fusion Team

Back to top