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
0
Question by N1nja · May 14, 2010 at 08:31 PM · dllmanaged

Properly using a Managed C# .Net DLL

I am trying to use a Managed C# .Net DLL for parts of my code that I wish to keep secret(by later obfuscating the DLL); Well, it turns out that I cannot use MonoBehaviour inherited classes from within my DLL inside of the Unity3d Editor. Initially I got the error, that my class couldn't be found(which is located in my DLL). Finally I got past that, by making a C# file in my project that inherited from my class in the DLL, but I quickly got another error that wouldn't let me access variables from my inherited class(which is inside the DLL);

This is becoming very annoying, and I hope someone knows a way around these issues. Thank you.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Lucas Meijer 1 · May 14, 2010 at 09:19 PM

Classes in your dll are just like any other classes, except that we don't support you assigning monobehaviours from your dll to a gameobject. It's fine to have a small script outside of your dll that does enherit from a class in your dll that has "the meat". If you cannot access members of that class, that sounds like an issue with the accesibility of those members. You might have them set to private, or internal. Make sure the type itself and the method/field in question are both public.

Comment
Add comment · 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
1

Answer by N1nja · May 14, 2010 at 09:38 PM

In my Managed C# DLL:

using UnityEngine;  
namespace My.Namespace  
{  
    public class MyCustomBehaviour : MonoBehaviour  
    {  
        public int myVariable = 0;  
    }  
}

Inside Unity Project:

using UnityEngine; using My.Namespace;

public class CustomBehaviour : MyCustomBehaviour
{
public int Variable {
get { return base.myVariable; }
set { base.myVariable = value; }
}
}

The above does not work. Any ideas?

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 Lucas Meijer 1 ♦♦ · May 15, 2010 at 01:38 PM 0
Share

That code looks perfect. Can you put the .dll online somewhere? Which version of Unity are you using? What is the exact error that you get?

avatar image
0

Answer by Phenotype · Nov 13, 2010 at 06:30 PM

I have the same issue. Unity requires your custom behaviour to derive directly from MonoBehaviour. The work around is to use your custom behaviour class as an adaptor. You then put your application logic in other classes that are referenced by your behaviour class.

Comment
Add comment · 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
0

Answer by boymeetsrobot · Nov 13, 2010 at 10:52 PM

Your issue is that you are using a Namespace with MonoBehaviour which is currently not supported in Unity. I had a similar issue. (see below quote from Unity scripting docs)

http://unity3d.com/support/documentation/ScriptReference/index.Writing_Scripts_in_Csharp.html

5.Don't use namespaces. Unity doesn't support placing your scripts inside of a namespace at the moment. This requirement will be removed in a future version.

Comment
Add comment · 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

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

No one has followed this question yet.

Related Questions

Import (mixed assembly) managed C++/CLI DLL plugin 0 Answers

Dll Call Back problem only in Standalone version 0 Answers

Using dll's from C#? 4 Answers

How do you compile a managed dll with mono/mcs targeting .net 2.0 or 3.5 for Unity? 1 Answer

Is there a garantee that managed Dll plugin will compile on to mobile? 0 Answers


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