Author Topic: Instantiate is null  (Read 4256 times)

ilovebird

  • Guest
Instantiate is null
« 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.

ilovebird

  • Guest
Re: Instantiate is null
« Reply #1 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Instantiate is null
« Reply #2 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.

ilovebird

  • Guest
Re: Instantiate is null
« Reply #3 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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Instantiate is null
« Reply #4 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.

ilovebird

  • Guest
Re: Instantiate is null
« Reply #5 on: June 20, 2013, 02:34:39 AM »
Thanks for you answer, I'm using NGUI recently, so I post here unthinkingly. :)