- Home /
Get types from UnityEngine.dll failed on RequireComponent
Any access to type RequireComponent in UnityEngine.dll will fail. For example: typeof(UnityEngine.UnityEngine.dll)
Reflecting will also fail due to it:
Console.WriteLine(typeof(UnityEngine.Animation).Name);
Assembly a = typeof(UnityEngine.Animation).Assembly;
Type[] tps = a.GetExportedTypes();
The last line will throw an exception saying that type RequireComponent is not in a valid format.
I compiled the code both in SharpDevelop and in XBuild in the Unity Mono folder (C:\Program Files (x86)\Unity\Editor\Data\Mono\bin). Both give the same result.
Is it a bug? If RequireComponent is not supposed to be used then it should be made private so that Assembly.GetExportedTypes() should not try to load it.
Any ways to get around it to get all public types in UnityEngine.Dll?
Answer by Mike 3 · Oct 08, 2010 at 10:00 PM
RequireComponent is supposed to be used (it's a public attribute which is pretty useful).
The unity 3 assembly has some protection against things in it being called by reflection, so I'm wondering if it's just hitting that
Not just reflection. Object creation will fail too: UnityEngine.RequireComponent rc = new UnityEngine.RequireComponent(typeof(UnityEngine.Animation));
Use it as an attribute not fail.
I'm not entirely sure why you'd ever want to instantiate it - It's a tag for the engine to add the component automatically. If you want to add a component, use AddComponent
Your answer
Follow this Question
Related Questions
Problem with reflection probe 0 Answers
Get List of Signatures of Messages to Monobehaviour 1 Answer
Fragment Shader pixel gets overwritten 1 Answer
Debug session of managed DLL in VisualStudio? 0 Answers
Require Component for Parent 2 Answers