How to know if multple gameobjects are of the same prefab?

Hello,

I have multiple gameobjects that have the same component but are of different prefabs with different component values. I need to be able to differentiate these gameobjects based on their prefab. Is there any way I can do this? I thought InstanceID would be the key but apparently it’s not.

At the moment I am just applying the InstanceID of the prefab to a field on the instanced prefab.

Thank you.

Assuming you’re not talking about an editor script, your current strategy is pretty much as good as you’re going to get. There’s no built-in way to check this in Unity. You could of course use an external mapping like a Dictionary that maps clones to their parents in some central place, but the effect is the same.

2 Likes

In Editor scripts, you can use PrefabUtility: Unity - Scripting API: PrefabUtility

1 Like

You could probably use something like this, many with name instead of tag???

throw everything into an array or debug.

Thanks for your answers guys. I guess I can understand why it doesn’t exist. Thanks for your solutions regardless!