UdonSharp icon indicating copy to clipboard operation
UdonSharp copied to clipboard

Please let [FieldChangeCallback] supports hooking to a callback method

Open JLChnToZ opened this issue 1 year ago • 0 comments

As we all know [FieldChangeCallback] is to instruct the U# compiler use specified property setter to handle a field value assigned from external source such as other udons or remote sync. But there's still a scenario that is not allowed, which is U# compiler don't like I directly assigns the value form other U# behaviors. Although we can use public exposed properties as workaround, but what if others want to use udon graphs to assign the value? This workaround makes the entry point not consistent. I even haven't said using properties require a few more udon instructions at least to get/set a value yet (under the hood).

That's why I want to propose extending the [FieldChangeCallback] functionality to let it specify a method. Instead of (rolling back the original value under the hood before hand) setting the value ourselves, this provides the raw input of the callback. We can use it to hook some event listener etc.

[FieldChangeCallback(nameof(OnValueChanged))]
public int someValue;

void OnValueChanged(int oldValue)
{
    Debug.Log($"The value has been changed from {oldValue} to {someValue}!");
}

JLChnToZ avatar Sep 21 '24 14:09 JLChnToZ