关于Unity中返回值的问题

我在UIManager.cs中有这么一串代码

    public T Open<T>() where T : UIForm
    {
        return this.Open(typeof(T)) as T;
    }

    public UIForm Open(Type type)
    {
        if (this.dictionary.ContainsKey(type) && this.dictionary[type] != null)
        {
            this.dictionary[type].transform.SetAsLastSibling();
            this.dictionary[type].Show();
            return this.dictionary[type];
        }
        GameObject gameObject = Resources.Load<GameObject>("UI/UIForm/" + type.Name);
        
        if (!gameObject)
        {
            return null;
        }

        Transform Canvas = GameObject.FindGameObjectWithTag("Main Canvas").transform;
        gameObject = Instantiate(gameObject, Canvas, false);
        gameObject.name = type.Name;

        UIForm component = gameObject.GetComponent<UIForm>();
        if (!component)
        {
            return null;
        }
        //component.gameObject.transform.SetParent(GameObject.FindGameObjectWithTag("Main Canvas").transform);
        component.transform.SetAsFirstSibling();
        component.Show();
        return component;
    }

当我在另一个脚本中调用这个方法的时候,UIManager.Instance.Open()会返回UIMain (UIMain),但是却无法赋值给this.mainMenu,好像也就导致无法实例化这个脚本,请问有什么办法解决这个问题?

  private UIMain mainMenu;
  private void OpenMain()
    {
        this.mainMenu = UIManager.Instance.Open<UIMain>();
 
    }

你debug一下UIManager.Instance.Open()看看是不是空