My Questions & Answers

What follows in this thread is a slow-motion stream-of-consciousness collection of questions I’ve come across that didn’t have easy, immediate answers for someone with no programming training and not much experience.

I’m still very much a newbie to Udon, C#, and programming generally. I have no training, and the only way I learn is to start doing, run into questions, and then answer them either by looking it up, asking someone, or doing an experiment.

My goal here is to answer my own questions somewhat fully, and use as many keywords as possible to make this thread searchable. Expect inaccurate or incomplete answers, and feel absolutely free to correct them.

Does the Start event never execute its flow if the UdonBehaviour (or the GameObject to which it’s attached) is not active when the player loads in?

It does execute. Start runs when the UdonBehaviour becomes enabled while the GameObject is enabled. I tested this by setting some text from the Start of an UdonBehaviour that was not running when I loaded in. I tried enabling the GameObject where it was disabled before, and I tried enabling the UdonBehaviour where it was disabled and the GameObject was enabled. Both executed Start.

OnEnable also runs when an UdonBehaviour is enabled, even where the GameObject was already enabled (which seems to differ a bit from the Unity documentation). Now I have more questions. Does Start execute each time an UdonBehaviour is enabled? If so, what’s the difference between Start and OnEnable?

References:

Today I learned that you can rotate a vector3 vector around any axis by multiplying Quaternion.AngleAxis by your vector.

More to the point, I learned that you can multiply vectors together with quaternions in the first place, using Quaternion.Multiply

image

start only gets executed once, OnEnable triggers repeatedly, start should only run once wheras the OnEnable will be run every time it’s turned on. If the script retains it’s state when being disabled Start won’t be run a second time but OnEnable will.

(Additionally, Start is run at the beginning of the initialization sequence of an object wheras OnEnable is at the end.)

Today I learned that sending an invalid index integer (particularly negative numbers, but probably also out of range) into an array element getter will halt / stop the UdonBehaviour, rather than just returning an invalid element value (which could be invalid checked).

If it’s wrapped in a try{} catch(){} block this behavior won’t happen since you can safely handle the error yourself :slight_smile:

Interesting, thanks. Does that exist in Udon Graphs?

Not sure, but it does in udon#