Unity Addressables 기본 조작

제갈도원·2026년 5월 26일
post-thumbnail

Unity Addressables 기본 사용법 - 에셋 등록부터 로드/언로드까지

이번에는 Unity의 Addressables를 사용해서 에셋을 등록하고, 코드에서 로드한 뒤 다시 언로드하는 간단한 테스트를 진행했다.

Addressables는 기존의 Resources.Load() 방식보다 에셋을 더 체계적으로 관리할 수 있게 해주는 시스템이다.
특히 프리팹, 이미지, 오디오 같은 리소스를 주소값 Key를 기준으로 불러오고 해제할 수 있다.

이번 글에서는 복잡한 원격 서버 배포나 콘텐츠 업데이트보다는, Addressables를 처음 사용할 때 필요한 기본 설정과 간단한 로드/언로드 흐름을 정리한다.


1. Addressables 패키지 설치

먼저 Unity에서 Addressables 패키지를 설치해야 한다.

Window > Package Manager > Addressables 설치

설치 후 Addressables Groups 창을 연다.

Window > Asset Management > Addressables > Groups

처음 사용하는 경우 Create Addressables Settings 버튼을 눌러 Addressables 설정 파일을 생성한다.


2. Addressables Group 설정

Addressables Groups 창에서는 에셋을 그룹 단위로 관리할 수 있다.

에셋을 Addressable로 등록하면 해당 에셋은 특정 Group 안에 들어가게 된다.

예를 들어 테스트용 프리팹인 IronBox.prefab을 Addressable로 등록하면, Addressables Groups 창에서 해당 프리팹을 확인할 수 있다.

여기서 중요한 것은 Address 값이다.
코드에서 Addressables로 에셋을 불러올 때 이 Address 값을 Key로 사용한다.

다만 Address 값을 너무 길게 쓰면 관리가 불편하기 때문에, 필요하다면 IronBox처럼 짧은 이름으로 변경해서 사용할 수 있다.


3. Cache Clear Behavior 설정

Group 설정에는 Cache Clear Behavior 옵션이 있다.

이 옵션은 새 버전의 번들이 로드되었을 때, 이전 버전의 캐시 번들을 정리하는 설정이다.

즉, 변경된 번들을 새로 받을 때 이전 캐시가 계속 남아있는 문제를 줄이는 역할을 한다.


4. Addressables 시스템 설정

Addressables Groups 창에서 상위 설정을 확인하면 Build, Diagnostics, Catalog 관련 옵션을 볼 수 있다.

Unique Bundle IDs

Unique Bundle IDs는 번들의 식별자 충돌을 줄이기 위한 옵션이다.

특히 콘텐츠 업데이트나 원격 번들을 사용할 때, 기존 번들과 새 번들이 같은 ID로 충돌하는 상황을 방지하는 데 도움이 된다.


Send Profiler Events

이 옵션을 체크하면 Addressables Event Viewer에서 로드/언로드 흐름을 확인할 수 있다.

Addressables를 테스트할 때 현재 어떤 에셋이 로드되어 있는지, 참조 카운트가 어떻게 변하는지 확인할 수 있어서 디버깅에 유용하다.


Build Remote Catalog

Build Remote Catalog는 원격 배포용 카탈로그를 생성하는 옵션이다.

카탈로그는 Addressables가 어떤 Key로 어떤 번들을 찾아야 하는지 기록해 둔 정보라고 보면 된다.

원격 서버를 사용하는 경우에는 Catalog 파일과 Bundle 파일을 서버에 올리고, 클라이언트가 실행 중에 해당 카탈로그를 기준으로 리소스를 불러오게 된다.

이번 테스트에서는 원격 배포까지 깊게 다루지는 않고, 해당 옵션이 어떤 역할을 하는지만 확인했다.


5. Addressable 에셋 등록

Addressables로 사용할 에셋을 등록하는 방법은 간단하다.

  1. Project 창에서 등록할 에셋 선택
  2. Inspector에서 Addressable 체크
  3. Addressables Groups 창에서 원하는 Group으로 이동
  4. Address 값을 확인하거나 원하는 Key로 변경

예시로 IronBox.prefab을 등록했다.

이제 이 프리팹은 Addressables를 통해 코드에서 로드할 수 있다.


6. Addressables 로드 / 언로드 테스트

버튼을 눌렀을 때 Addressable 프리팹을 생성하고, 다시 버튼을 눌렀을 때 생성된 오브젝트를 해제하는 방식으로 진행했다.

프리팹을 생성할 때는 Addressables.InstantiateAsync()를 사용한다.

Addressables.InstantiateAsync(_addressableKey, _spawnPoint.position, Quaternion.identity)

이 함수는 Addressable Key에 해당하는 프리팹을 비동기로 로드한 뒤, 씬에 인스턴스로 생성해준다.


7. 테스트 코드

using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

public class PrefabsTest : MonoBehaviour
{
    // 어드레서블 Key
    [SerializeField] private string _addressableKey = "IronBox";

    // 생성 위치
    [SerializeField] private Transform _spawnPoint;

    // 생성된 오브젝트
    private GameObject _spawnedObject;

    // Addressables 로드 핸들
    private AsyncOperationHandle<GameObject> _handle;

    public void Load()
    {
        // 중복 생성 방지
        if (_spawnedObject != null)
        {
            DebugTool.Log("이미 오브젝트가 있음", DebugType.Addressable);
            return;
        }

        Addressables.InstantiateAsync(_addressableKey, _spawnPoint.position, Quaternion.identity).Completed += handle =>
        {
            if (handle.Status == AsyncOperationStatus.Succeeded)
            {
                _handle = handle;
                _spawnedObject = handle.Result;

                DebugTool.Log("로드 성공", DebugType.Addressable);
            }
            else
            {
                DebugTool.Log("로드 실패", DebugType.Addressable);
            }
        };
    }

    public void Unload()
    {
        if (_spawnedObject == null)
        {
            DebugTool.Log("언로드할 오브젝트가 없음", DebugType.Addressable);
            return;
        }

        Addressables.ReleaseInstance(_spawnedObject);

        _spawnedObject = null;
        _handle = default;

        DebugTool.Log($"{_addressableKey} 언로드 완료", DebugType.Addressable);
    }
}

8. InstantiateAsync란?

InstantiateAsync()는 Addressables에 등록된 프리팹을 비동기로 불러오고, 씬에 생성까지 해주는 함수다.

일반적인 Instantiate()와 비슷해 보이지만 차이가 있다.

Instantiate(prefab);

이 방식은 이미 메모리에 있는 프리팹을 복제한다.

반면 Addressables의 InstantiateAsync()는 Addressable Key를 기준으로 에셋을 찾고, 필요한 경우 로드한 뒤, 씬에 인스턴스를 생성한다.

public static AsyncOperationHandle<GameObject> InstantiateAsync(object key, Transform parent = null, bool instantiateInWorldSpace = false, bool trackHandle = true)
{
    return m_Addressables.InstantiateAsync(key, parent, instantiateInWorldSpace, trackHandle);
}  

이런 인자값을 넣어주면 됩니다.

흐름은 다음과 같다.

Addressable Key 확인
↓
해당 에셋 로드
↓
프리팹 인스턴스 생성
↓
생성된 GameObject 반환

9. Release와 ReleaseInstance 차이

Addressables에서 중요한 부분은 로드보다 언로드다.

로드한 방식에 따라 해제 방식도 맞춰야 한다.

LoadAssetAsync로 불러온 에셋
→ Addressables.Release(handle)

InstantiateAsync로 생성한 인스턴스
→ Addressables.ReleaseInstance(instance)

이번 테스트에서는 InstantiateAsync()로 프리팹을 생성했기 때문에, 해제할 때는 ReleaseInstance()를 사용했다.

Addressables.ReleaseInstance(_spawnedObject);

단순히 Destroy()만 사용하면 Addressables의 참조 카운트가 제대로 정리되지 않을 수 있다.
따라서 Addressables로 생성한 인스턴스는 Addressables 방식으로 해제하는 것이 좋다.


10. 테스트 흐름 정리

1. IronBox 프리팹을 Addressable로 등록
2. Address 값을 Key로 설정
3. 버튼 클릭 시 InstantiateAsync로 프리팹 생성
4. 생성된 오브젝트를 변수에 저장
5. 다시 버튼 클릭 시 ReleaseInstance로 언로드
6. 중복 로드와 빈 언로드 상황을 예외 처리

+ 서버를 이용한 설정

Addressables Groups → Profile → Manage Profiles → Addressables Profiles

나중에 서버를 이용해서 설정을 할 때 여기에 주소를 설정해줘야 합니다.

마무리

Addressables의 가장 기본적인 사용 흐름을 확인했다.

정리하면 Addressables는 단순히 에셋을 불러오는 기능이 아니라, 에셋을 Key 기반으로 관리하고 로드/언로드 흐름까지 제어할 수 있는 시스템이다.

가장 간단한 방식으로 프리팹을 등록하고, InstantiateAsync()로 생성한 뒤, ReleaseInstance()로 해제하는 흐름을 테스트했다.

실제 프로젝트에서는 여기에 더해 다음과 같은 부분을 추가로 고려해야 한다.

중복 로드 방지
참조 카운트 관리
씬 전환 시 리소스 유지 여부
BGM처럼 씬이 바뀌어도 유지될 리소스 처리
원격 카탈로그 및 서버 배포
Addressable Key 관리 방식

우선 Addressables의 기본 조작 방식과 로드/언로드 흐름을 이해하는 것이 중요하다.

0개의 댓글