x


How to know if a GameObject is a prefab?

I have a a list of objects via Resources.FindObjectsOfTypeAll.

I want to know who are Prefabs and who are on scene.

more ▼

asked Feb 18 '12 at 01:58 AM

Veehmot gravatar image

Veehmot
378 14 18 25

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

In the editor, use PrefabUtility.GetPrefabParent(theGO); ( http://unity3d.com/support/documentation/ScriptReference/PrefabUtility.html ) if you have a game object

At runtime you can't find it out any longer and its not needed cause you can not create or modify them anyway

Alternatively, don't use this function to get the resources but specific type ones. Anything thats a texture, mesh, audio or movie file is never a prefab, anything else so all component / monobehaviours are always prefabs as they can't exist in resources otherwise

more ▼

answered Feb 18 '12 at 06:52 PM

Dreamora gravatar image

Dreamora
3.2k 1 4 25

Just for completeness

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

Thanks.

Feb 23 '12 at 12:50 AM Veehmot

"At runtime you can't find it out any longer and its not needed cause you can not create or modify them anyway"

I don't think this is true, at least any more. I've run into the exact same problem as the OP. I need to find all cameras in the scene active or inactive and make changes to them. Using FindObjectsOfTypeAll it also finds the prefabs. When I make modifications during runtime like this then stop the player, those changes persist in the Prefab :O

Mar 14 at 01:06 PM xpation
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2075
x1664
x1252
x216
x3

asked: Feb 18 '12 at 01:58 AM

Seen: 2546 times

Last Updated: Mar 14 at 02:18 PM