Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development

Tarek El Eryan
Tarek El Eryan
1,768 Points

The thing you want to instantiate is null.

I have been staring at this problem for a few hours and I can't for the life of me figure it out. I am hoping someone here can help me see the problem:

void Start () {
    shapeList.Add (cushion);
    shapeList.Add (diamond);
    shapeList.Add (drop);
    shapeList.Add (marquise);
    shapeList.Add (oval);
    shapeList.Add (radiant);
    shapeList.Add (round);  
    shapeList.Add (trilliant);

    playerShape = shapeList [Random.Range (0, shapeList.Count)];
    Debug.Log (playerShape); // this returns randomly chosen GameObject

    //assign player GameObject to the player prefab
    playerAvatar = playerShape as Object;

    // referencing Canvas to be set to GameObject Canvas
    canvas = GameObject.Find ("Canvas");

    // referencing GlobalVars script and assigning it to globalVars
    GlobalVars globalVars = canvas.GetComponent<GlobalVars> ();

    // referencing CanSize script and assigning it to canSize
    CanSize cansize = canvas.GetComponent<CanSize> ();

    // determining X & Y Spawn Points
    spawnAreaX = cansize.canWidth / 2;
    spawnAreaY = cansize.canHeight / 2;

    // instantiate GameObject at the randomly chosen xyz values to the position of the enemy object
    player = Instantiate(playerAvatar, new Vector3(spawnAreaX, spawnAreaY, globalVars.positionZ), Quaternion.identity) as GameObject;