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 How to Make a Video Game Pickups Add Pickup Particles

Missing reference exception : the game object is disappered but u r still trying to access it , i cant pickup the fly

i cant pickup the fly after 5 to 10 seconds pls help any one

using UnityEngine; using System.Collections;

public class FlyPickup : MonoBehaviour {

[SerializeField]
private GameObject pickupPrefab;

void OnTriggerEnter(Collider other) {

    if (other.CompareTag ("Player")) {


        // if the collider other is taggeed with "player"...

        // .. add the pickup particles..
        Instantiate(pickupPrefab, transform.position, Quaternion.identity);
        Destroy (gameObject);
    }

}

}

Helgi Helgason
Helgi Helgason
7,599 Points

Is the Collider component on the flies mark as a trigger, there should be checkbox called IsTrigger.

Izzatilla Karimov
Izzatilla Karimov
9,284 Points

I also have the same issue, The Fly Is Trigger is checked, but the tag is selected to untagged. And the player is selected to player tag but Is Trigger is unchecked. I believe thats how it has to be but still doesn't work. The error says..

UnityException: Tag: player is not defined. FlyPickup.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/FlyPickup.cs:12)

1 Answer

Tamar Chalker
seal-mask
.a{fill-rule:evenodd;}techdegree
Tamar Chalker
UX Design Techdegree Student 29,121 Points

I'm having the same problem - I get MissingReferenceException: The object of type "Object" has been destroyed but you are still trying to access it. Did I miss something somewhere, I have watched the videos a couple times now.