How do I detect if a game object exist?

In the scene?

btw, i'm using javascript.

If you know the name of the object:

if (GameObject.Find("WhateverItsCalled") != null)
{
    //it exists
}

using UnityEngine;

public class MyMonobehaviour : MonoBehaviour
{
    [SerializeField]
    private GameObject go;

    void Start()
    {
        if (go.scene.IsValid()) {
            // go is an instance of an object that's present in the scene
        } else {
            // go is an instance of a prefab
        }
    }
}

this works :slight_smile:

		if (GameObject.Find ("Character(Clone)") != null) {
			Debug.Log ("get one");
		} else {
			Debug.Log ("not there");
		}

thx

Try this :

var sceneName = testObject.scene.name;
if (sceneName != null)
{
	// this object is on scene
}
else
{
	// this object is a prefab, not instantiate on any scene
}

Im using this to check if the gameObject “pickleThing” is present like this:

if(GameObject.find(“pickleThing”) == null)
{
//insert code for showing text “mass extinction” here.
}

Also give me the prefab version if this is incompatible with prefabs (also is this compatible with csharp?)