U
U
Uncle Bogdan2021-10-22 19:42:50
Unity
Uncle Bogdan, 2021-10-22 19:42:50

Do I need to assign fields in Awake?

I can do like this:

// В начале еще RequireComponent

private Rigidbody _rigidbody;

private void Awake()
{
    _rigidbody = GetComponent<Rigidbody>();
}


But at the same time, I can add the SerializeField attribute and put Rigidbody in the inspector.

Which option is more correct? GetComponent is a dumb option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Farawa, 2021-11-15
@Farawa

you can do it this way, it depends on the situation, for example, if 5-10 objects do this, then it's okay, but if 100+, then it's better to make a prefab and specify it through [sf]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question