Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by nice_shot · Dec 16, 2018 at 03:05 PM · editor-scriptingassetdatabasecomponents

Find all components in project

Hello,

I'm writing an editor extension that requires selecting component names out of a list of all available components in the project. Similar to how the "Add Component" dropdown works.

Is there a way to get all the available components in the project? I've tried using AssetDatabase but that doesn't cover built in components like Rigidbody.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RobAnthem · Dec 16, 2018 at 03:18 PM 0
Share

Well... it's probably not what you want to hear, but you may want to look into Reflection. Otherwise you'll be brute-forcing it and hoping you didn't forget something. However if you're only looking for certain stuff, you can do it that way. Like..

 //Asset database crap
 if (myAsset.GetComponent<Rigidbody>())
 {
     rigidbodies.Add(myAsset.GetComponent<Rigidbody>());
 }
 if (myAsset.GetComponent<$$anonymous$$eshCollider>())
 {
     meshColliders.Add(myAsset.GetComponent<Rigidbody>());
 }
 //etc (obviously this kind of brute force is VERY inefficient)

Although thinking about it you could create a database that scours the assets, and adds a EDITOR ONLY component to every asset that contains an ID and relevant info, you'd just need to make sure to add a Reset function to piggyback off the Reset event of monobehaviours for whenever a new component is added.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by nice_shot · Dec 18, 2018 at 06:50 AM

Indeed it looks like the best way to find all components is using reflections. Here is a snippet that shows how to do this:

 var componentTypes = System.AppDomain.CurrentDomain.GetAssemblies()
     .SelectMany(assembly => assembly.GetTypes())
     .Where(type => type.IsClass && type.IsSubclassOf(typeof(Component)))
 ;
 
 foreach (var type in componentTypes) {
     Debug.Log(type.FullName);
 }

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image RobAnthem · Dec 18, 2018 at 03:02 PM 0
Share

Glad to hear you figured it out, if you are doing this dynamically though you may still want to use the internal Reset function for monobehaviours so that you can catch and record when new scripts are added. However if you're acquiring all components every time you need them, then I wouldn't bother with Reset.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

108 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

ObjectField Get object type(Asset, Scene Object) 2 Answers

Serialization issue with ScriptableObject 0 Answers

Save Components setting for reuse 1 Answer

ScriptableObject List variable doesn't save if created through script, works fine if created through Inspector 2 Answers

AssetDatabase.Refresh() no longer recompiling my generated scripts 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges