How to use manual synced variables? Are they supported by U#?

I am studying the classical synced vars and I am at a point that I can grasp how they work. But it seems I dont know how to use them in the new “manual” mode. Is there a specific function I should use to “trigger” the “manual” sync? I searched in all documentation and could not find anything (surely my fault) clearly explainin how to trigger that manual thing.
The following U# script is working with continuous syncing BUT not when set to manual. What should I add to make it work using Manual syncing? Thanks for any help or to referring me to some clearly explained example of this very important new functionality.

using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

public class TestingSynch : UdonSharpBehaviour
{
    [UdonSynced] int counter = 0;
    public override void Interact()
    {
        Networking.SetOwner(Networking.LocalPlayer, this.gameObject);
        counter += 1;
        Debug.Log("Changed value to "+counter);
        
    }
    public override void OnDeserialization()
    {
        Debug.Log("OnDeserialization");
    }

    public void Show() {
        Debug.Log("Value of counter is "+counter);
    }
}

dont understand this answer. There are a lot of people even here in this forum who are using usharp on a daily basis and it makes so sense. Anyway I solved the problem myself, and am going to publish now the solution…

I found myself the solution… The only missing instruction I probably didnt see but found out delving in many other github project is really simple RequestSerialization(). Now it works. Here is the working script:


using UdonSharp;
using UnityEngine;
using VRC.SDKBase;
using VRC.Udon;

public class TestingSynch : UdonSharpBehaviour
{
    [UdonSynced] int counter = 0;
    public override void Interact()
    {
        Networking.SetOwner(Networking.LocalPlayer, this.gameObject);
        counter += 1;
        Debug.Log("Changed value to "+counter);
        RequestSerialization();  //                     <---- this was the missing line!
        
    }
    public override void OnDeserialization()
    {
        Debug.Log("OnDeserialization");
    }

    public void Show() {
        Debug.Log("Value of counter is "+counter);
    }
}

2 Likes

Udon Sharp isn’t a custom script…

Udon Sharp compiles things down to an udon behavior the same way udon nodes does it. And it has the same restrictions udon nodes has.

This is why udon# has been, and continues to be, an allowed way of writing udon code. Since there’s no real difference between the two aside from how you write stuff.

1 Like

可以给个视频教程吗

Can you give a video tutorial

I can do that. I usually do tutorials in Italian, but can do one in English :slight_smile:

That would be the best, or you can recommend some tutorials to me.I am an intern. Our company is mainly doing VR game development. I have some unity and C# foundation. I hope you can give me some suggestions for learning VRCHat or what more important knowledge points I should learn.

I have just published a sort of tutorial in English on Youtube: VRChat Udon # Syncronization methods on shared variable. - YouTube

1 Like