Am I missing something or is there actually not a way to load a class by it’s fully qualified name?
So the class itself can be in a namespace, but I have to use a name for the class that I know will not collide with anything, which sucks.
Am I missing something or is there actually not a way to load a class by it’s fully qualified name?
So the class itself can be in a namespace, but I have to use a name for the class that I know will not collide with anything, which sucks.
you mean like this:
using UnityEngine;
using System.Collections;
namespace MyNamespace {
public class Test : MonoBehaviour{
}
}
using UnityEngine;
using System.Collections;
public class TestApply: MonoBehaviour{
void Update(){
MyNamespace.Test test = gameObject.GetComponent<MyNamespace.Test>();
}
}
Works perfectly for me.
It used to not work, but it does now. I currenlty use 4.3.4.f1 and it works fine.
There is one caveat I’ve noticed. If you have optional/default args, the compiler throws an exception that the class name does not match the file name.
i.e.
using UnityEngine;
namespace SomeNamespace
{
public class Test : MonoBehaviour
{
public void Foo(float a, bool someModifier = false)
{
}
}
}
Type type = Type.GetType(myFullyQualifiedName);
gameObject.AddComponent(type);
Ya I should have been more clear. By load I meant using AddComponent. The above works.