Ultimate Beginners Guide To Udon

What is udon?
Udon is a new way to set up events and actions in your world using graphs and nodes to have a better visualization of your scripts, such as a mirror you toggle on and off. I’ll be using this as the main example throughout this thread.

Nodes are like events and actions you can connect to each other with “noodles”. Most of them are similar to how programs worked in sdk2 so its transferable how your scripts work.

So to get started with udon, you need to create a component called a udon behavior. Don’t forget to use colliders (not mesh) so that interact and mouse down toggles work.

Then you create a new graph and open it. When you get into arrays later on, you can see how you can use the same graph for multiple objects, like a universal toggle script so you don’t need a new graph every time.

So here we have variables. I used game object as an example because usually you’ll be interacting with the nature of objects. The public selection allows you to assign a game object to that variable in the component, when you search for a variable to use (gameobject, component, bool, int etc) you’ll notice brackets on the end, those are just array versions of that variable.

for this first example i’ll show how you can assign a mirror toggle, I made a cube that will be clickable and toggles the mirror behind it on and off. You can see where i put the mirror prefab in the public variable spot so the graph knows which object in the scene to affect.

as you can see, if you created in sdk2, its very similar logic and just a different way to lay it all out.

for the next part i’ll touch on networking. Ownership and networking is a bit different than sdk2. There’s only two options for syncing, local and all (global) and to get actions to save globally you need to use deserialization which i’ll cover later on. So to make an action local or global you use a couple udon behaviors, event custom, and sendcustomnetworkevent.

How these two works, is event custom goes into the main input of your graph and name it something, like in this case maybe “mirrortoggle”. Then you create a sendcustomnetworkevent node and call it the same name as your custom event cause its the event its calling on. Kinda like a function. and put your interact event input into the sendcustomnetworkevent node, then set the output to either all (global) or owner (local) You’ll see what i mean in the example below:

Now say you want to make a single graph to use for multiple different situations. Then you can use For loops to read arrays of objects. an example would be a gameobject variable named mirrors. In the component itself where you put in the objects into the public variable, it lets you set how many objects are in the array and assign multiple objects into the array.

Now those are the basics on how its all laid out. There is a lot that you can do with udon and tons of nodes to choose from so there’s a lot to look through, but this is the basic logic on how it all works.

Now the last thing i’ll cover is the event on Deserialization. This is an event that automatically happens every second. It checks for updates to synced variables and updates to everyone in the server. So if we interact with an object like a mirror, and want it to stay on for everyone in the instance and for new players to the instance, then we have to do two things. Update the active state for both the person who interacted with it, and on deserialization for everyone else in the server. So basically we have to create our graph almost twice.

So for the mirror, You would save the active state as a public, synced, bool so that others can read the deserialization update themselves and update the object state for themselves.so in my example i’ll have a bool variable called “on” to save the mirror state on or off

I hope this was easy to understand, please let me know if you need any help or advice on this thread