How do i synch Canvas components in a networked room?

I have a button and a text object and I can change the text of the button when the user clicks the button.

How would I implement a network message to synch the text between multiple networked players?

Original Post on Discord

by user 563549194137239552

You can “manually” send messages to all connected users to a room using this.context.connection.send("message-key", {<message-object>})
and listen to messages using this.context.connection.beginListen using the key

Automatically would be adding a @syncField("method_name") typescript decorator to your typescript field (“method_name” is the method on the component you want to be called whenever the value has changed, this is optional)

I’d say syncField is more on the experimental side, we use it in some places but not extensively yet.

It’s great for simple things.

For persistence there are couple things to be aware of:

if you add a guid to your message body (when you send a js object) the message will be stored in the backend and sent to newly connected users when they enter the room. This is how e.g. the sync transforms remember their position when you move them around and come back in the room later

You can also add a magic field dontSave to that model if you want to tell the server to NOT save that model ever. Not sure if you need that but just so that you’ve heard it :slightly_smiling_face:

Very cool! I was looking for somerthing like the decorator… I’m used to using Photon and Mirror so the concept of marking things to synch makes a lot of sense

by user 563549194137239552

Yea i love that decorator. Recently used it to add Skybox sync within a few seconds. Let me know if you run into issues tho - as said we haven’t used it in complex scenarios yet

I guess you would use dontSave if you want each user to experience something from the same initial starting point like an onboarding gimmick

by user 563549194137239552

Good information on the guid. Do you think that should be added to needle-engine-support/documentation/networking.md at main · needle-tools/needle-engine-support · GitHub?

by user 106501920008445952

Yes totally - I’d want to double check what options we currently have on the server side too since it’s been a couple of months since we touched that (which is a good thing I guess :sweat_smile: )