Picking from the editor or get in Start function? Whats the best for performance?

Hi,
I’m learning the unity from youtube/udemy tutorial projects and i have a question.

In example: i have a cube object and inside of it there is Rigidbody + C# Script. And i wanna access the rigidbody from the script.

Some masters getting the own rigidbody from editor
[SerializeField] private Rigidbody _rigidBody;

And some of other masters getting from the Start function

private RigidBody _rigidBody;

private void function Start()
{
      _rigidBody = GetComponent<Rigidbody>();
}

Quote Joe-Censored:

2 Likes

As said, it’s fine in start. Just don’t do it every frame.
Caching it I guess would be faster, but the only way to know is to benchmark it. Don’t think it’s worth experimenting with it tho

1 Like

Okay guys thank you for your answers, i will note that!

1 Like