Best way to Get Component in a Script in Unity!

preview_player
Показать описание
To avoid getting a Null Reference Exception in Unity, use TryGetComponent() instead of GetComponent() to access components in your scripts🙂👍

#unitytips #gamedev #unity2d #IndieGameDev #Coding #shorts
Рекомендации по теме
Комментарии
Автор

Realistically you're only saving one line of code. You're still either going to have to make sure you aren't handling nulls elsewhere, or have a check for a null.

adamarzo