Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: ilovebird on June 17, 2013, 01:26:37 AM

Title: Instantiate is null
Post by: ilovebird on June 17, 2013, 01:26:37 AM
I have a Singleton Class called "BLSingleton", which has a public GameObject prefabPop, I drag a prefab to it, and a function:
public void showPopview() {
    GameObject popView = (GameObject) Instantiate(prefabPop);
}

but in other class when I call BLSingleton.GetInstance().showPopview(), there is an error:
ArgumentException: The thing you want to instantiate is null.

Anybody knows why? Thanks very much.
Title: Re: Instantiate is null
Post by: ilovebird on June 17, 2013, 02:02:34 AM
I modified the singleton class to common class called "BLUtility" like this:

public GameObject prefabPop;
public void showPopview ()
{
    GameObject popView = (GameObject) Instantiate(prefabPop);
}

and in another class, I called showPopview()
BLUtility utility = new BLUtility();
utility.showPopview();

but the problem is still the same.
Title: Re: Instantiate is null
Post by: ArenMook on June 18, 2013, 12:37:47 AM
Your question doesn't seem to have anything to do with NGUI. Your "prefabPop" was likely never set to anything.
Title: Re: Instantiate is null
Post by: ilovebird on June 19, 2013, 03:41:55 AM
I have dragged a gameobject to prefabPop,
and in the same class ("BLUtility.cs"), I can Instantiate(prefabPop) correctly
but in another class("test.cs"), I try:

BLUtility utility = new BLUtility();
utility.showPopview();

it was not right.
Title: Re: Instantiate is null
Post by: ArenMook on June 19, 2013, 01:17:43 PM
If BLUtility derives from MonoBehaviour, you can't just "new" it. You have to AddComponent.

Again, I don't see how this is related to NGUI.
Title: Re: Instantiate is null
Post by: ilovebird on June 20, 2013, 02:34:39 AM
Thanks for you answer, I'm using NGUI recently, so I post here unthinkingly. :)