コガネブログ

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

【Unity】Player content must be built before entering play mode with packed data.

概要

f:id:baba_s:20200404224837p:plain

Addressable Asset System で Play Mode Script を
「Use Existing Build」にしている状態で Unity を再生した時に

Player content must be built before entering play mode with packed data.
This can be done from the Addressables window in the Build->Build Player Content menu command.

上記のエラーが出て Unity が再生できない場合は

f:id:baba_s:20200404225028p:plain

Addressables Groups ウィンドウの「Build > New Build > Default Build Script」を押して
アセットバンドルをビルドする

これで、Unity を正常に再生できるようになる

おまけ

アセットバンドルをビルドすると、

【Unity プロジェクト】\Library\com.unity.addressables\StreamingAssetsCopy\aa\【プラットフォーム名】\

上記のフォルダに

  • catalog.json
  • link.xml
  • settings.json

が出力されるが、この内の「settings.json」が存在しない場合に
前述のエラーが発生する仕組みになっている

protected override TResult BuildDataImplementation<TResult>(AddressablesDataBuilderInput builderInput)
{
    var timer = new System.Diagnostics.Stopwatch();
    timer.Start();
    var settingsPath = Addressables.BuildPath + "/settings.json";
    if (!File.Exists(settingsPath))
    {
        IDataBuilderResult resE = new AddressablesPlayModeBuildResult() { Error = "Player content must be built before entering play mode with packed data.  This can be done from the Addressables window in the Build->Build Player Content menu command." };
        return (TResult)resE;
    }