How to transfer ownership to sync strings?

Hi, so I’ve been trying to create a keyboard system in vrchat using udon, and I am pretty much done with everything, except I hit an annoying wall. as noted from:

synced objects can be set by other than the master by using .SetOwner.
However, I am not exactly sure what would the object be to make others sync the string.
I tried setting the object to the whole keyaboard gameobject, and I tried setting it to the gameobject of the UItext that has the string, but neither worked.

I am wondering if someone knows how to make it work :persevere:
Thanks in advance

Edit:
part of the answer from @stackoverflow

There has to be a string variable in an udon graph/script where synced is checked for that variable. Get the gameObject that carries the above mentioned udonBehaviour and call setOwner for that gameObject, and then call setProgramVariable for that udonBehaviour, finally update the synced string to the ui text component to be displayed.
It seems that the ownership transition takes time and immediately setting a synced variable after asking for ownership may fail? (I am not sure if the delay is unavoidable.)

1 Like

The delay is unavoidable. The time is takes is the time it takes for the update your setOwner has been sent with to complete.

So you would have to create a buffer that waits for you to be the owner, then sync the value.

Edit; You also got to take into account the time it takes for the synced variables to be transmitted across the network.

1 Like

If it would possibly take hundreds of milliseconds before the client could write to the synced variable, then I guess some “lock” has to be implemented to avoid concurrency(for example asking for ownership at the same time)?

In a way yes, though, it depends on the complexity of your system.

You could utilize SendCustomNetworkEvent with this, and have that “lock” the behaviour, until the “new” owner sends the unlock event again.

Thanks for the inspiring idea. :laughing:

@PhaxeNor @stackoverflow
Thank you both for replying.
I’ve successfully made the ownership transfer work. and as you have mentioned, the delay was unavoidable. What I did to fix this is that I created an if statement with the (is owner) node graph, to make sure that it only sets the text variable after the ownership is taken. and since I have my string synced by a late update, everything worked out great.
:heart:

1 Like