Engine/Unity

유니티 GetChild() vs GameObject.Find() 어느 것이 속도가 빠를까.

VirtualDever 2023. 2. 11. 20:34

구글링을 해보았더니, 나와 똑같은 의문을 가진 개발자가 있었다.

유니티 포럼에서도 여러 의견이 나뉘는데, 내가 봤을 때는 1 => 2 => 3 순으로 느리다.

따라서 유니티 인스펙터에 컴포넌트를 걸어두고 사용하자!

 

 

참고 문서

https://docs.unity3d.com/ScriptReference/Transform.GetChild.html

 

Unity - Scripting API: Transform.GetChild

If the transform has no child, or the index argument has a value greater than the number of children then an error will be generated. In this case "Transform child out of bounds" error will be given. The number of children can be provided by childCount.

docs.unity3d.com

https://docs.unity3d.com/ScriptReference/GameObject.Find.html

 

Unity - Scripting API: GameObject.Find

This function only returns active GameObjects. If no GameObject with name can be found, null is returned. If name contains a '/' character, it traverses the hierarchy like a path name. For performance reasons, it is recommended to not use this function eve

docs.unity3d.com