x


How can I select all prefabs that contain a certain component?

I had to change the data format of one of the components we use frequently. I thought I could just quickly write a script to search through the entire project, find any prefabs containing the component, and then run some code to convert the data. But I'm not actually sure where to start -- how do I iterate through prefabs in editor code? I'm familiar with finding active game objects (i.e. in the scene/hierarchy) but not those in the project. I must be tired, but I just can't find out where to start (I looked in EditorApplication, EditorUtility, searched here, etc).

more ▼

asked Nov 26 '10 at 04:43 AM

Molix gravatar image

Molix
4.8k 15 27 66

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

1 answer: sort voted first

Hi,

AssetDatabase.LoadAllAssetsAtPath(<string>)

I think this is what you need given your explanation. You will end up with a list of all objects in that path. Look at the rest of AssetDatabase functions, there is a lot related to that.

Then you could use

EditorUtility.GetPrefabType(<object>) 

As you iterate through the return of AssetDatabase.LoadAllAssetsAtPath or whatever in the scene, if GetPrefabType() returns PrefabType.Prefab as a result, then you have a prefab.

Hope it helps,

Bye,

Jean

more ▼

answered Nov 26 '10 at 08:47 AM

Jean Fabre gravatar image

Jean Fabre
3.1k 68 74 103

Thanks; would I be correct in assuming that LoadAllAssetsAtPath does not check child folders? So I'll need to do that too. Ok, thanks a lot!

Nov 26 '10 at 03:13 PM Molix
(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:

x1663
x1249
x44

asked: Nov 26 '10 at 04:43 AM

Seen: 1639 times

Last Updated: Nov 26 '10 at 04:43 AM