230925_ TryGetComponent

Minsang Kim·2023년 9월 25일
0

TIL

목록 보기
30/41

TryGetComponent

public bool TryGetComponent(out T component)

가끔씩 이럴 때가 있다 GetComponent를 하고 싶은데, 있나 없나 모를 때. 그래도 그냥 가져왔을 때는 메모리 할당을 발생시켜 Garbage Collection을 일으킬 수 있다.

그래서 TryGetComponent를 쓴다.
찾고 싶은 컴포넌트를 제너릭 자리에 넣고, 있으면 component에 넣어주고 true를 반환, 없으면 그냥 false를 반환하는 심플하지만 유용한 기능이다.

profile
게임만 하다가 개발자로

0개의 댓글