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
1
Question by Firelights · Sep 03, 2018 at 12:13 PM · componentreflectiontypeassembly

Getting all component types (even those not on the scene)

Hello, I am making an editor window which calls functions based on two fields, component name and function name.

Before I call the function, I'd like to verify if the component name is valid. For that, I need a list of all component types.

Is there any way to know that? I've tried using reflection and loading assemblies, but couldn't find the right assembly file with the components.

Thank you in advance,

Comment
Add comment
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

1 Reply

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

Answer by Bunny83 · Sep 08, 2018 at 12:52 AM

I just made a ComponentDatabase utility class. It can be used to get a list of all components that are derived from a certain base class or that implement a certain interface (GetTypes method).


In addition you can search for components by name by using FindComponent. Note FindComponent returns a "TypeNode" which is a simple linked list. This is used because since we have namespace support the same component name can refer to different classes.


GetAllTypes() returns an IEnumerable of all Component types in your project including build in components. Abstract classes are not included in the list.

Comment
Add comment · Show 7 · 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 Firelights · Sep 13, 2018 at 10:30 AM 0
Share

Wow, you just did my homework! Thank you so much for all the effort put into this. I owe you a big one.

avatar image Bunny83 Firelights · Sep 13, 2018 at 10:58 AM 1
Share

Do you mean literally "homework" (school / uni)? Or did you just mean the task you had to solve in a project of yours? Unity answers is not meant for homework questions. Though in this case i guess others might find it useful as well.

avatar image Firelights Bunny83 · Sep 14, 2018 at 02:57 PM 0
Share

I meant a task, all we need here is some guidance, you had no obligation to write all that code ( or share it ) and for that I'm very grateful!

Also, about the code, there are some problems... I did a quick test and there are some abstract classes, like "Behaviour". Your code seems to check for abstract classes. But this one still passes (on GetAllTypes() )

Show more comments

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

91 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

Related Questions

FileNotFoundException (System.reflection) when using SmarFox2.dll 1 Answer

Loading Script from Asset Bundle in iOS and WebGL. 2 Answers

Generate Script in Editor Script and GetType() returns null. 3 Answers

How do I find the name and value for each variable of a script component, using Unity script? 2 Answers

How Do I pass an unknown class to a function? 2 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