How can I test whether an object is a prefab or an instance?

Is there a way to test whether an object is a prefab or an instance besides trying to find the same object instanced using one of the FindObject or FindGameObject style methods?

Very interesting question ;-) I think there's no way to test that from within your game. But I'm not sure what the use case for such a test would be. In your game (while playing), I think whether an object is a prefab or not doesn't really matter unless you want to instantiate the prefab "again". But even in that case, you could also duplicate existing objects (non-prefabs); and if you want to instantiate a prefab, you need to have a reference to it - and by having that reference you'd know it's a prefab. So, personally, I don't see much use in such a check from within the game - but I might be missing something (feel free to comment or edit your question to add a use case).

In the editor (for editor scripting), it's a completely different story, of course. There, it can be very important to know what kind of object you're dealing with. And in that environment, it's also possible: See PrefabUtility.GetPrefabType.

PrefabUtility.GetPrefabParent(gameObject) == null && PrefabUtility.GetPrefabObject(go) != null; // Is a prefab

It says here

that PrefabUtility.GetPrefabType( Object obj ) returns PreabType.None if obj is not a prefab.

This won’t work if you change the name of the game object, but since instantiated objects start with “(Clone)” as part of their name, you can test for that:

if (gameObject.name.Contains("(Clone)")
{
    // not a prefab
}
else
{
    // probably a prefab
}

As of Unity 4, I have found that using

gameObject.activeInHierarchy

has become useful for situations like this should the rare occasion arise.

In editor code you can use EditorUtility.IsPersistent to determine if an object is from the scene or from an asset.

No, but since prefabs have to be instantiated manually it shouldn't be too difficult to keep track of such things yourself.

You can check for a selected prefab like this:

private static bool HasSelectedPrefab()
    {
        if (Selection.activeObject)
        {
            UnityEngine.Object obj = PrefabUtility.GetPrefabObject(Selection.activeObject);
            if (obj)
            {
                return true;
            }
        }

        return false;
    }

You can use an editor script to populate a prefab with a listof your prefab references to compare with at runtime.

Edit:
Today I found out about GameObject.hideFlags so it can be used for finding if the gameobject is prefab or not. if hideFlags is HideInHierarchy then it’s a prefab.
Please ignore the rest of this post…

I found the answer and I posted the whole code in here : http://forum.unity3d.com/threads/i-found-the-solution-for-checking-if-a-gameobject-is-prefab-or-not.272958/

bool isAPrefab = UnityEditor.PrefabUtility.IsPartOfAnyPrefab( gameObject );
bool isPrefabInstance = UnityEditor.PrefabUtility.IsPartOfPrefabInstance( gameObject );
bool isFreeGameobject = !isAPrefab;

Anno Domini 2019

How about asking, which scene does the gameobject belong to? An asset (prefab) will not be a part of any scene