Quick Flow
Single은 기존 loaded scenes를 내리고 새 scene으로 바꿉니다. Additive는 기존 scenes를 유지한 채 새 scene을 올리므로, 누가 unload하고 어떤 scene이 새 GameObject의 기본 소유자가 될지까지 정해야 합니다.
| 목적 | API | 이어서 정할 것 |
|---|---|---|
| 메뉴에서 게임으로 완전 교체 | LoadSceneAsync(name, Single) | persistent service와 save handoff |
| HUD·월드 chunk·overlay 추가 | LoadSceneAsync(name, Additive) | SetActiveScene, binding, UnloadSceneAsync owner |
| 로딩 화면 뒤 전환 | allowSceneActivation = false | 0.9 progress 대기와 activation 조건 |
Loading과 activation
LoadSceneAsync는 background loading을 시작하고 AsyncOperation으로 완료 상태를 봅니다. allowSceneActivation = false면 operation 진행률은 보통 0.9에서 멈춘 뒤 true가 될 때 scene을 활성화합니다. 이 상태에서 다른 async operation이 진행을 기다릴 수 있으므로, 로딩 UI의 취소·최소 표시 시간·activation 조건을 한 owner가 관리합니다.
using UnityEngine;
using UnityEngine.SceneManagement;
public sealed class SceneLoader : MonoBehaviour
{
public async Awaitable LoadGameplay(string sceneName)
{
AsyncOperation load = SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Single);
load.allowSceneActivation = false;
while (load.progress < 0.9f)
{
await Awaitable.NextFrameAsync();
}
load.allowSceneActivation = true;
while (!load.isDone)
{
await Awaitable.NextFrameAsync();
}
}
}Single load에서는 기존 scene object가 unload되므로, 그 object를 참조하던 service는 다음 scene의 target을 다시 찾거나 reference를 clear해야 합니다. DontDestroyOnLoad가 이 binding 문제를 자동으로 해결하지는 않습니다.
Additive 소유권
Additive load 뒤에는 둘 이상의 loaded scene이 존재합니다. SceneManager.GetActiveScene()은 새 GameObject가 기본적으로 배치될 active scene을 결정하므로, gameplay scene을 additively 올린 뒤 그 scene을 active로 만들 필요가 있는지 확인합니다. global service, UI overlay, world region 중 누가 active scene이어야 하는지는 서로 다를 수 있습니다.
Scene gameplay = SceneManager.GetSceneByName("Gameplay");
SceneManager.SetActiveScene(gameplay);
// 나중에 이 region을 올린 owner가 해제합니다.
AsyncOperation unload = SceneManager.UnloadSceneAsync(gameplay);Unload 전에 해당 scene의 object를 보는 Camera, event listener, singleton cache, Addressables handle을 정리합니다. additively 올린 scene을 매번 누적하거나, 여러 manager가 같은 scene을 unload하려 하면 Missing Reference와 double cleanup이 생깁니다.
자주 틀리는 부분
| 증상 | 원인 | 수정 |
|---|---|---|
| 로딩 progress가 0.9에서 멈춤 | allowSceneActivation이 false | activation 조건을 만족하면 true로 변경 |
| 새 object가 예상 scene에 안 생김 | Additive 뒤 active scene 미지정 | SetActiveScene 필요 여부를 명시 |
| HUD가 scene 재진입마다 쌓임 | load owner는 있지만 unload owner가 없음 | load/unload를 같은 lifecycle owner에 둠 |
| persistent service가 죽은 Player를 참조 | Single unload 뒤 cache를 유지 | sceneLoaded/unloaded에서 reconnect·clear |
| scene 이름이 같은데 다른 것을 load | 이름만 전달해 첫 일치 scene을 선택 | Build Settings path 또는 unique name 사용 |
참고 링크
3 sources