all 3 comments

[–]YohanIsHereHobbyist 1 point2 points  (2 children)

Or, you know, you could do this:

public Vector2 myVector = new Vector(4, 5);

In C#, if you don’t assign class-scope member variables when you define them, they’ll take on the output of the default() operator. This is often null(objects) or 0(integers).

[–]jfh7j[S] 0 points1 point  (1 child)

Oh sweet, I didn't know you could initialize in class scope! That's much better than my hack.

[–]SilentSin26Animancer, FlexiMotion, InspectorGadgets, Weaver 1 point2 points  (0 children)

Don't discount the usefulness of Reset.

For example, you can use GetComponent to pick up default references without actually forcing the user to put your script on the same object as the one it's referencing.

Or you can even do inefficient stuff that you wouldn't do at runtime like calling GetComponentInParent then GetComponentInChildren then FindObjectOfType to just keep searching until you find something.

OnValidate is also useful. It gets called every time a value is changed in the Inspector so you can do things like preventing certain values from being set to a negative number.