以下の内容はhttps://baba-s.hatenablog.com/entry/2018/02/02/211000より取得しました。


【Unity】Internal_CreateGameObject is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead.

概要

using UnityEngine;

public class Example : MonoBehaviour
{
    private GameObject gameObject = new GameObject();
}

上記のように、メンバ変数の定義のタイミングで
new GameObject() を記述すると

Internal_CreateGameObject is not allowed to be called 
from a MonoBehaviour constructor (or instance field initializer), 
call it in Awake or Start instead.

このエラーが発生します
エラーを回避するには

using UnityEngine;

public class Example : MonoBehaviour
{
    private GameObject gameObject;

    private void Awake()
    {
        gameObject = new GameObject();
    }
}

new GameObject() の記述を Awake や Start に移動します




以上の内容はhttps://baba-s.hatenablog.com/entry/2018/02/02/211000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14