actionScript書きの日記

アラフォーFlashデベロッパのブログ。actionscriptやobjective-cを経て、現在はUnity、Spine、AfterEffectsがメイン。

LoadAssetAsyncで動的に生成したPrefabのSetParentを実行してエラーが出る件

前提

「Addressables.LoadAssetAsync<GameObject>」関数で動的に生成したPrefabに対して「SetParent」関数を実行すると、

Setting the parent of a transform which resides in a prefab is disabled to prevent data corruption.

とエラーが出る。

 

対処法

生成したPrefabをインスタンス化していないのが問題。

Instantiate関数でインスタンス化してからSetParent関数を実行すればエラーは出ない。

 

こちらの記事に助けていただいた。感謝申し上げる。

ninagreen.hatenablog.com