- Home /
Question by
Ben Humphreys · Jun 05, 2013 at 01:36 PM ·
c#typeaddcomponent
AddComponent with runtime type checking
I'm trying to add a component from a string at run-time (I have component names stored in a simple XML file).
I'm trying to do something like this in C#, but it dies with "The type or namespace name "T" could not be found"
Type T = Type.GetType(compName);
T x = myObj.AddComponent(compName) as T;
What am I doing wrong?
Comment
Your answer
Follow this Question
Related Questions
C# string as type for AddComponent 2 Answers
C# - passing a Type var to GameObject.AddComponent 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Creating a Script at runtime, and adding it to an object... 1 Answer