Closed PintsizedSix40 closed 4 years ago
You have to use SetProgramVariable(name, value)
Thanks for the bug report! I made the error messages clearer about this in a recent commit that's going to be in a release tomorrow. This is because Udon only exposes a subset of functions that exist in Unity. If you get any errors about methods, properties, or fields not being exposed or found it means that Udon does not currently expose that function for people to call. Sometimes this is for security reasons and sometimes it's just because VRChat hasn't realized that the function should be exposed.
In this case you can have the same functionality by instead calling SetProgramVariable()
on the UdonBehaviour
and passing the name of the variable and the value.
I'm working on more documentation, but if you want to set a variable on another UdonSharpBehaviour, you can store it as the actual type and then set the field on it as you normally would in C#. So you can do gameobject.GetComponent<YourType>().name = value;
Describe the bug in detail: Using UdonBehavior.publicVariables.TrySetVariableValue results in a compile error. The error output is
System.Exception: Could not find Udon field accessor VRCUdonCommonInterfacesIUdonEventReceiver.__get_publicVariables__VRCUdonCommonInterfacesIUdonVariableTable
.Provide steps/code to reproduce the bug: Get a gameobject with a UdonBehavior, get the component using
(UdonBehaviour)gameobject.GetComponent(typeof(UdonBehaviour))
, then attempting to set the variable using.publicVariables.TrySetVariableValue("name", value)
.(UdonBehaviour)gameobject.GetComponent(typeof(UdonBehaviour)).publicVariables.TrySetVariableValue("name", value);
Expected behavior: The variable is set correctly.
Additional Information: