How Do I Pass A Event Through Another Udon Script to Change A Variable?

So, I have a object that has a variable.
Basically, I made it so, if the integer reaches a value, than the object gets set to inactive.

I want to be able to change this value with other objects outside of this particular UdonGraph.

(Basically, similar to how global variables work.)

Idk if its still relevant, but I think what you want is SetProgramVariable node.

It allows you to change the variable of another Udon Graph.
So if I understood it right - the thing you are trying to achieve is something like this:

  • You have an integer variable
  • You update that integer variable from a different object, for example, if the player clicks on it
  • When that variable reaches a certain value - you disable the object

How I would approach this:

  • Add a new custom event, e.g. “CheckValue” to your main UdonGraph that has the integer (make sure it is marked as public).
  • That custom event would be wired to the logic that checks if the integer reached the value
  • In a different UdonGraph (the one you want to change that integer from), add a new variable of type UdonBehaviour, make it public, save the graph and drag and drop the first graph into it in the inspector
  • Add a SetProgramVariable node and plug in that UdonBehaviour variable into the instance slot
  • Select your integer variable from the dropdown
  • Pass the new value into the value slot
  • Add SendCustomEvent node and plug the same UdonBehaviour variable into the instance and select CheckValue in the dropdown

Here’s the example graphs:

Main Graph:

Other Graph:

Whenever you interact with the “Other Graph” object - it will set the counter integer variable to 15 and run the CheckValue event, which will cause the “Main Graph” object to disable itself, as the counter value is now > 10

Hope that wasn’t too confusing!

1 Like