- Home /
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,
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.
Wow, you just did my homework! Thank you so much for all the effort put into this. I owe you a big one.
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.
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() )
Your answer
Follow this Question
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