对象实例化返回null

时间:2018-12-08 05:17:59

标签: c# unity3d null instantiation argumentexception

由于某种原因,当尝试实例化此特定游戏对象时,我得到了

  

ArgumentException:要实例化的对象为null。

我在文件夹中标记了我正在使用的模型的特定预制件,因此我不知道为什么会遇到此特定错误。

这是我的代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using TMPro;

public class Spawnpoint : MonoBehaviour
{
    public int spawnGroup;

    [HideInInspector]
    public bool inUse = false;

    public GameObject Spawn(NPCManager.NPC_ENUM typeID)
    {
        string prefabName = NPCManager.Instance().getPrefabName(typeID);

        GameObject go = (GameObject)Instantiate(Resources.Load(prefabName));

        if (go == null)
        {
            Debug.Log("cannot find refab \"Models/" + prefabName + "\"");
            return null;
        }

        go.SetActive(false);

        go.transform.position = transform.position;
        go.transform.rotation = transform.rotation;
        float scale = NPCManager.Instance().getScale(typeID);
        go.transform.localScale = new Vector3(scale, scale, scale);

        TextMeshProUGUI nameText = go.transform.FindDeepChild("BillboardText").GetComponent<TextMeshProUGUI>();
        nameText.text = NPCManager.Instance().getName(typeID);

        AIController.MyAIController ctrl = go.GetComponent<AIController.MyAIController>();
        ctrl.destination = go.transform.position;
        go.SetActive(true);

        return go;
    }
}

Here is what my particular Resources file looks like

我觉得我已经尽力解决了这个问题。有人有建议吗?

谢谢!

0 个答案:

没有答案