コガネブログ

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

【Unity】Addressables のビルドでどこに時間がかかっているのか調べる方法

概要

com.unity.scriptablebuildpipeline@1.19.3/Editor/Shared/BuildTasksRunner.cs

上記のファイルに記載されている BuildTasksRunner.Run メソッドの

foreach (IBuildTask task in pipeline)
{
    var sw = Stopwatch.StartNew();  // ★
    {
        try
        {
            if (!tracker.UpdateTaskUnchecked(task.GetType().Name.HumanReadable()))
                return ReturnCode.Canceled;

            ContextInjector.Inject(context, task);
            ReturnCode result;
            using (logger.ScopedStep(LogLevel.Info, task.GetType().Name))
                result = task.Run();
            if (result < ReturnCode.Success)
                return result;
            ContextInjector.Extract(context, task);
        }
        catch (Exception e)
        {
            BuildLogger.LogError("Build Task {0} failed with exception:\n{1}\n{2}", task.GetType().Name, e.Message, e.StackTrace);
            return ReturnCode.Exception;
        }
    }
    sw.Stop();  // ★
    Debug.LogWarning( $"{task.GetType().Name}: {sw.Elapsed.TotalSeconds:0.00} 秒" );  // ★
}

foreach の中で Stopwatch を使用すれば、ビルドのどこに時間がかかっているのかを

f:id:baba_s:20211126120602p:plain

調べられるようになる