Udon Graph variable access

So I’m new to unity scripting and Udon. I’m working through a unity scripting course and trying to mirror it in Udon Graph. Hopefully this is not too stupid of a question.

Question: How do I access the contents of a defined variable of another Udon Graph script?

I did a test and it seems like all public variables (names) are local and only accessible inside the Udon Graph script they are created in. Meaning if I use the exact same variable name in another Udon Graph, its considered a different variable container. Is this correct? Could someone demonstrate how I to define a udon graph variable in one object, and access and modify it in another object with a different udon graph script.

if you’re learning normal programming, why not just use udon#? GitHub - MerlinVR/UdonSharp: An experimental compiler for compiling C# to Udon assembly

I’m trying to learn both methods. I have friends that only use Udon Graph. I would like to be able to design in both.

Unlike C#, In the Udon Graph there’s no direct access to public variables from other Udon behaviours. Instead you must use an UdonBehaviour.GetProgramVariable Node. The Node accepts an Udon Behaviour Variable as the “Instance Input”, this is the other Udon program you’re trying to get a public variable from. You also have to provide a String value, which is the exact name (Same capitalization and all) of the variable you’re trying to get from the other program. Here is an example in the graph;

You can also do the opposite and Set the value of a public variable on another program via a UdonBehaviour.SetProgramVariable Node.

As for the question of variable containers, there is a concept in programming called “Scope”. I’ll give a general loose explanation that will give you a basic understanding. All variables made within the Variable tab of an Udon Program, public or not, exist within the Scope of that program’s instance. This means that, yes, you can call two public variables, in two separate programs, the same thing, and assign them their own values without interference (Though you may not want to as to not get confused between the two). You can even have 2 or more instances of the same program running without conflicts either. Names are just things we give variables to refer to them when we program to make it easy for us. When programs are compiled and run, they are assigned a unique address in memory, which is the computer’s way to refer to a variable. This is just a loose explanation, I’m sure you’ll learn more in depth explanations as you continue to code. If you require any further information, just ask.

Hmmm I may be doing this wrong. The value I’m trying to grab is from the game object “Canvas” which as the Udon behaviour “TextSliderUpdate” and a float in that called “sliderValue” in that behaviour.

I dragged the “Udon Behaviour (script)” into the new Udon behaviour. Then attempted to access it using your above example.

It looks like they changed the way the UdonBehaviour.GetProgramVariable Node interface works, it now has a pull down menu. (1) The pull down contains all the current Udon behaviour’s variables if nothing is hooked up. (2) If I add the Canvas UdonBehaviour, the pull down is dimmed. (3) If I force a string of “sliderValue” and Play I get the following error:

[<color=yellow>UdonBehaviour] Could not find symbol sliderValue; available: [__arg0_6,__instance_2,__format_3,UGsizeModifyer,__arg0_1,UGisRotated,__message_0,__message_1,__message_2,__message_3,__message_4,__message_5,__format_6,__arg0_4,StartingMessage,__format_1,__instance_1,__Boolean_0,__Boolean_1,UpdateMessage,__Single_1,__format_4,__Single_2,__arg0_2,UGnewName,__arg0_5,__format_2,__instance_0,Canvas,__Single_0,__arg0_0,__Vector3_0,__format_5,__arg0_3,__symbolName_0,__value_1,__value_0,__value_2,__format_0]
UnityEngine.Debug:LogError(Object, Object)

In 3 you are doing it correctly by providing it a string value, however this error only appears when the program is searching itself for the variable called sliderValue, which does not exist. This means that your canvas variable isn’t pointing to the canvas object in the scene. Make sure in the inspector that it is pointing to it by dragging and dropping the canvas object into the canvas public variable slot, like this;

That was the issue, thanks!