1. 오브젝트 풀링이란?
오브젝트를 생성하고 파괴할 때 마다 메모리를 할당하고 해제하는 일이 반복되는데, 미리 오브젝트들을 생성해 놓고 필요할 때에만 사용하면 메모리 관리를 최적화 할 수 있다.
enemyPool = new GameObject[count];
for (int i = 0; i < count; i++)
{
enemyPool[i] = Instantiate(enemyPrefab, PoolPosition, Quaternion.identity);
enemyPool[i].SetActive(false);
}
이후 오브젝트가 필요할 때 SetActive(true); 하여 사용한다.
'✏️ 이론 > 최적화' 카테고리의 다른 글
| [ Unity ] GetComponent / TryGetComponent (0) | 2023.09.21 |
|---|