Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 TnTGaming · May 11, 2011 at 06:09 PM · pluginclassdllcustom

How to call a custom object from a C# dll

Problem:

(function, file, and class names changed to protect the innocent)

So I have a C# dll named CSharpDLL

so I do this in my unity C# script.

using CSharpDLL;

// later on

private CSharpDLL.CustomObjectName foo;  // note that this works just find and doesn't cause any errors

// later on

(I press foo. and mono recognizes the object and shows me the names of all of its member functions, sweet this must be working)

foo.voidMethod(); // this causes the error

foo = new CSharpDLL.CustomObjectName(); // this causes the error and yes there is a default constructor in the dll class

Both of these create the following error in Unity :

Internal compiler error. See the console log for more information. output was: Unhandled Exception: System.TypeLoadException: Could not load type 'CSharpDLL.CustomObjectName' from assembly 'CSharpDLL, Version=1.1.2.1, Culture=neutral, PublicKeyToken=null'.

Note that my CSharpDLL is in the plugin folder.

Question : How do I create an object that is defined in a C# dll and use it?

Thanks

Comment
Add comment · Show 1
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 equalsequals · May 11, 2011 at 06:16 PM 0
Share

j/w, are you using the global namespace for your .dll?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · May 11, 2011 at 09:20 PM

Don't put managed C# dlls into the plugin folder. The plugin folder is for native code dlls. If you compiled a "normal" C# dll, unity will import it like any other asset. Unity will strip away the namespace and import the classes into the global namespace (that happends at least with classes that are derived from MonoBehaviour). I'm not sure if all classes are handled that way. I've done only some tests with dlls and unity.


edit

I've just created a test dll that looks like this:

using System; using System.Collections.Generic; using UnityEngine;

namespace ClassLibrary1 { public class DLLTest { public DLLTest() { Debug.Log("Hello World"); } }

}

And in Unity when i execute this line i get the "Hello World" printed.

ClassLibrary1.DLLTest tmpObj = new ClassLibrary1.DLLTest();

As i said, just place the dll somewhere in your assets. If it contains classes that are derived from MonoBehaviour it will show up in the project view as sub-assets of your dll, so you can drag-drop them onto GameObjects

Comment
Add comment · Show 2 · 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 TnTGaming · May 12, 2011 at 03:29 PM 0
Share

So does using UnityEngine; need to be in the C# DLL then?

avatar image Bunny83 · May 12, 2011 at 04:15 PM 0
Share

Well i've always add the UnityEngine.dll as assembly. If you do that you can use the whole API there. I'm not sure if you have to, i guess it's not necessary but in the end it won't hurt since you build for Unity ;)

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

Can I use my own input device? 4 Answers

PropertyDrawer: Enum to select extended class 0 Answers

How to create a custom function out of script (See the answer for more) 1 Answer

Cant link PLUGIN.DLL with PLUGIN-EDITOR.DLL 1 Answer

Unity plugins 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