(I’ve been acting mostly as a tools developer and development support programmer for the past couple years, so my opinions below are tinted by that. My primary goal has been to enable other developers to get their games implemented quickly and as robustly as possible.)
More code means more bugs.
If you’re working with anyone else, especially artists and level designers, they and you will both appreciate being able to do as much as possible within the editor. You don’t want artists mucking around in your scripts. The editor also gives you lots of validation that you’d have to implement manually in a code-only solution. Take this script for example:
public class MyClass : MonoBehaviour {
[Serializable]
public class MyNestedData {
public string myString;
}
public MyNestedData data;
void Start() {
Debug.Log(data.myString);
}
}
If you add it using the editor, the inspector will serialize it and initialize data.
If you add this using GameObject.AddComponent(), data will be null. When Start() runs, you’ll get a NullReferenceException.
Now of course you could add an initializer to the variable declaration:
public MyNestedData data = new MyNestedData();
but as the programmer you have to remember to do this. And this is just one example of many little things that the editor does for you.
Attributes like [RequireComponent] are also semantic definitions. Placed at the top of a class definition, [RequireComponent] makes it clear that the class requires a certain component:
[RequireComponent( typeof(Animator) )]
public class Character : MonoBehaviour {
...
This makes it pretty clear that Character requires Animator.
You could bury a check inside Awake(), but it’s harder to notice:
void Awake() { // <-- starts somewhere fairly deep down in the script file
var animator = GetComponent<Animator>();
if (animator == null) {
// Need to add code to handle the case where there's no Animator on the GameObject.
Debug.LogError("This component requires an Animator!");
}
}