Failure to load MonoBehaviour objects from a plugin

Here's a brief illustration of my problem : say I have 2 C# plugins, A.dll and B.dll.

A.dll contents : ObjectA which inherits from MonoBehaviour

B.dll contents : ObjectB which inherits from ObjectA

Within Unity, 'ObjectA' is correctly listed in the Project view under 'A', while no MonoBehaviour is found in B.dll

As soon as ObjectB inherits directly from MonoBehaviour, 'ObjectB' is listed in the project view under 'B'.

Any ideas why?

2 Answers

2

I've never tried such an inheritance, but maybe it has something to do with the namespaces. Unity imports all classes found inside the dll into the global namespace. From Unity's view ObjectA is in the global namespace, maybe that's why it doesn't recognise the base class of ObjectB.

By the way: plugins in unity mostly refers to native code plugins (that have to be placed in the plugin folder). "Normal" managed c# dlls can be placed anywhere in the assets folder.

For anyone still experiencing the same problem, I’ve found a workaround. My solution was to use the Microsoft tool ILMerge, which merges two or more DLLs into one single library. By setting up this tool as a post build command from within VS2010, I could keep my libraries separated while still getting all Monobehaviours correctly shown in Unity.

Might not fit every purpose, but was good enough in my case.