#TIL #unity 씬 로드 전에 함수 호출

씬 로드 전에 함수를 호출할 방법이 있을까?

class MyClass
{
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
    static void OnBeforeSceneLoadRuntimeMethod()
    {
        Debug.Log("Before first scene loaded");
    }

RuntimeInitializeOnLoadMethod 어트리뷰트를 사용하면 된다. 먼저 찾은 <Best way to initialize static class not attached to a GameObject> 글에선 에디터와 독립(standalone) 실행을 분리해서 구현했던데, 하나로만 해도 잘 된다.

Feedback plz <3 @ohyecloudy, ohyecloudy@gmail.com

A Random Post