Get name of inherited type?

Hi folks,

how can I access the name of a type inherited from MonoBehaviour?

I’ve got a code block that looks like this:

var objCollection : List.<MyBehaviour>;
for(var obj in objCollection)
  Debug.Log("Type: " + (typeof obj));

where MyBehaviour inherits from MonoBehaviour. The collection however contains elements of other types that themselves inherit from MyBehaviour. I’d like to get the name of the “deepest” type in that inheritance tree. Debug.Log only writes “Type: MyBehaviour” to the log.

I’d like to invoke specific actions depending on the type of ‘obj’.

Any idea?

Thanks a lot!

Sure, the typeof operator just determines the type of the variable, which is of course MyBehaviour since that’s the type stored in the List. To get the dynamic type you have to use obj.GetType() which returns the System.Type object for the object that is referenced by this variable.