728x90
Sound의 경우 게임 어디에서도 사용되는 Object다. 어떤 Object는 Scene이 바뀌면서 삭제됐다가 필요한 경우 다시 생성되지만, 계속 필요한 Object는 삭제되는 행위 자체가 쓸데없는 메모리 사용이다.
이때 DontDestroyOnLoad()를 사용해주면 게임이 꺼질 때까지 Object가 삭제되지 않고 필요할 때 언제든 꺼내 쓸 수 있다.
https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
Unity - Scripting API: Object.DontDestroyOnLoad
The load of a new Scene destroys all current Scene objects. Call Object.DontDestroyOnLoad to preserve an Object during scene loading. If the target Object is a component or GameObject, Unity also preserves all of the Transform’s children. Object.DontDest
docs.unity3d.com
728x90
'공부 > Unity' 카테고리의 다른 글
[Unity] Player가 가라앉아서 움직이는 에러 해결하기 (0) | 2022.05.04 |
---|---|
[Unity] 코루틴(Coroutine)이란? (0) | 2022.05.03 |
[Unity] Mathf란 (0) | 2022.05.02 |
[Unity] ArgumentException 오류 (0) | 2022.05.02 |
[Unity] Debug 디버깅과 오류 해결하기 (0) | 2022.05.02 |