Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
5
Question by Jormungandr · Jan 27, 2010 at 11:13 PM · editor-scriptingdllmono

Components Inside A DLL

I'm in the process of developing a library for use with third-party Unity projects. Ideally, I'd like to have certain MonoBehaviours which are defined within that library (a compiled DLL) and then exposed within Unity. But, Unity doesn't seem to pick up on the existence of MonoBehaviours inside a DLL (even if I try to add them explicitly through an editor script).

The workaround I've found so far is to subclass my library MonoBehaviour in a script file, and add the subclass as a component. This seems to work so far, but is there a way to expose the library class to the editor directly?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
5

Answer by Daniel Sperry 2 · Mar 05, 2011 at 06:41 PM

From 3.0 you can use monobehaviours from dlls. The dll need to be added to any folder named Plugins inside the Assets folder.

Once there you can use the Project window at the Unity Editor to explore the DLL contents and drag and drop the monobehavior into any game object.

It works just fine!

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image yoyo · Nov 23, 2012 at 08:52 PM 0
Share

(As of Unity 3.5.6) It works unless you want a generic base class. In scripts, I can have $$anonymous$$yBaseComponent<T> : $$anonymous$$onoBehaviour and $$anonymous$$yDerivedComponent : $$anonymous$$yBaseComponent<string>, but in a DLL this doesn't work. (Yup, this is a bug.)

avatar image yoyo · Dec 12, 2013 at 09:14 PM 0
Share

(As of Unity 4.3.1) It works, but there is a Unity Editor bug that prevents you from having a component in one DLL that derives from a component base class in a different DLL.

avatar image llMarty · Dec 17, 2014 at 11:55 PM 0
Share

In 4.6.1f1 the bug still exists. I cannot inherit from a class from an extern DLL that inherits from $$anonymous$$onoBahiour. When I add the reference it works until I simulate the game. Also I created some scripts in my own external library but I cannot browse them in the project explorer.

avatar image
3

Answer by Ricardo · Jan 28, 2010 at 08:49 AM

{EDIT: this is old information for Unity 2.x} Unity does not yet support MonoBehaviours inside a DLL. See the comments on this blog post by AngryAnt. He mentions:

Unity unfortunately does not yet support MonoBehaviours and ScriptableObjects in external assemblies. Remember that your external code is still not a first class citizen in your Unity runtime, but an external assembly

As AngryAnt himself is a Unity employee, I expect that's coming from the source.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Brian-Kehrer · Jan 28, 2010 at 09:13 PM 0
Share

That blog entry is actually quite interesting as well... Thanks AngryAnt, wherever you are.

avatar image
1

Answer by jashan · Jan 28, 2010 at 08:50 AM

Unfortunately not - but I think that would be very worthwhile feature request. Currently, Unity only keeps "assets" in the project pane; and MonoBehaviours are only considered "assets" when they exist as actual files. Another limitation you have there is that MonoBehaviours can't be put into namespaces (they must always exist in the root namespace).

For your use case, I think the ideal solution would be if Unity could look into DLLs and search for anything subclassing "MonoBehaviour" and then allow you to "expand" the DLL (it must be in your Assets/-folder anyways). Then, it could also use the namespace hierarchy you provide in the DLL, so if you have, for instance "Jormugandr.Scripts.TheUberCharacterController", in your DLL JromungandrProTools.dll, and the user has put this into Assets/External/JromungandrProTools.dll, Unity could show this in the project pane as follows:

External
+ JromungandrProTools(.dll)
  + Jromungandr
    + Scripts
      + TheUberCharacterController

I'd love to have that - but keep in mind: This is just a potential solution that should be filed as feature request at: Unity Feedback

EDIT 1: With that in place, you could not drag'n'drop TheUberCharacterController onto any game object you wish.

EDIT 2: Ah, I just found out that there already is a feature request for this, so go, vote it up ;-) ... see Scripting: Ability to define MonoBehaviour in DLLs

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image 3D-Magic-VR · Nov 04, 2011 at 08:45 PM 0
Share

Currently in version 3.4 you can create dlls with monodevelop (inclided) and frankly it's easy, it is also possible to make a dll with code for editor.

avatar image JimmyJJeeter · May 12, 2012 at 09:00 AM 0
Share

Does the code for editor then need the resulting dll in an Editor folder?

avatar image yoyo · Nov 23, 2012 at 08:50 PM 0
Share

Yes, any scripts in Editor folders should be moved into a DLL which itself goes in an Editor folder. (e.g. Plugins/Editor)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Dynamically loading scripts 4 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Build from script 3 Answers

MonoDevelop keeps switching to .Net 3.5 0 Answers

'EventSystems' does not exist in the namespace 'UnityEngine'... 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges