コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】InitializeOnEnterPlayMode と RuntimeInitializeOnLoadMethod の実行順

実行順

  1. InitializeOnEnterPlayMode
  2. RuntimeInitializeLoadType.SubsystemRegistration
  3. RuntimeInitializeLoadType.AfterAssembliesLoaded
  4. RuntimeInitializeLoadType.BeforeSplashScreen
  5. RuntimeInitializeLoadType.BeforeSceneLoad
  6. RuntimeInitializeLoadType.AfterSceneLoad

検証環境

  • Unity 2022.1.23f1
  • macOS Monterey バージョン 12.5.1
  • MacBook Pro 2021

検証用ソースコード

using UnityEngine;

internal static class Example
{
#if UNITY_EDITOR
    [UnityEditor.InitializeOnEnterPlayMode]
    private static void InitializeOnEnterPlayMode() => Debug.Log( "InitializeOnEnterPlayMode" );
#endif

    [RuntimeInitializeOnLoadMethod( RuntimeInitializeLoadType.SubsystemRegistration )]
    private static void SubsystemRegistration() => Debug.Log( "RuntimeInitializeLoadType.SubsystemRegistration" );

    [RuntimeInitializeOnLoadMethod( RuntimeInitializeLoadType.AfterAssembliesLoaded )]
    private static void AfterAssembliesLoaded() => Debug.Log( "RuntimeInitializeLoadType.AfterAssembliesLoaded" );

    [RuntimeInitializeOnLoadMethod( RuntimeInitializeLoadType.BeforeSplashScreen )]
    private static void BeforeSplashScreen() => Debug.Log( "RuntimeInitializeLoadType.BeforeSplashScreen" );

    [RuntimeInitializeOnLoadMethod( RuntimeInitializeLoadType.BeforeSceneLoad )]
    private static void BeforeSceneLoad() => Debug.Log( "RuntimeInitializeLoadType.BeforeSceneLoad" );

    [RuntimeInitializeOnLoadMethod( RuntimeInitializeLoadType.AfterSceneLoad )]
    private static void AfterSceneLoad() => Debug.Log( "RuntimeInitializeLoadType.AfterSceneLoad" );
}