C# - AddComponent Vs GetComponent

Is it more or less costly to use GetComponent() than AddComponent() ?

I’ve been wondering about this for awhile, haven’t seen any documentation or comments to clarify.

For example, if I want an AudioSource component on an Object, inside of a script would it be cheaper to add the component in the scene view, then cache it with GetComponent, or would it be cheaper to add the component on scene loading, and cache it as you create it, e.g. aud = gameObject.AddComponent();

I believe the difference won’t be noticeable except if you call the function multiple times each frame.

I think it’s a premature optimization to choose between those two functions.

IMHO, the best is to not call those functions at all and reference them using the inspector.


// Drag & drop the rigidbody component in the inspector
private Rigidbody myRigidbody ;


private Rigidbody myRigidbody ;

private void Awake()
    myRigidbody = GetComponent<Rigidbody>();