[Question] Optimization Editor vs Script?

Hello,
From what i’ve read here in this topic

Getcomponent (specially in childred) are heavy for performance.

Does setting it on the editor makes difference?
and is it bad practice to use Getcomponent (writing it on the script) instead of just assigning it from the Editor (if possible to assign).

Tldr: should i prioritize assigning components from editor than assigning it from the script?
Thanks!

There aren’t many occasions when you can assign a component to a variable in the editor.


While it is true that GetComponent is a heavy call, the real point isn’t about avoiding the call itself but avoiding its use within the context of a repeating method like Update or FixedUpdate. Where possible the component should be obtained, saved to a variable within code and referenced from that variable in repeated code. When that can’t be done in Start or Awake (there can be synchronization issues with those), the best alternative is to perform lazy initialization of the member variable (simply check it for null and call GetComponent once when it is null).