Tasharen Entertainment Forum
Support => NGUI 3 Support => Topic started 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.
-
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.
-
Your question doesn't seem to have anything to do with NGUI. Your "prefabPop" was likely never set to anything.
-
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.
-
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.
-
Thanks for you answer, I'm using NGUI recently, so I post here unthinkingly. :)