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
1
Question by SteveFSP · May 19, 2010 at 04:29 AM · plugin

Considerations/Gotcha's when Creating a C++ CLR Plugin in VS2008

What are the special considerations and gotcha's involved in creating a C++ CLR plugin for Unity with Visual Studio 2008? I ask this because I'm having problems and have read several posts indicating that others are having problems as well.

Reference:

C++ dll plugin problem (Unanswered - My test projects are similar to the one he describes.)

From the forums (They are discussing a lot of complex hacks in the post. But interspersed are simple test cases that are also showing problems.)

I'm limiting this question to VS2008 for the following reason:

  1. I downloaded the test project "MCPPLIB.zip" from the above mentioned thread. (Note: This is a VS2003 project.)
  2. I copied its pre-built DLL into the Unity assets folder and tested access to it. Everything was good.
  3. I opened the MCPPLIB project and converted it to VS2008 format, including the build fixes described at link text. (Left the targeted framework at .NET 2.0)
  4. I built the DLL and copied it to the Unit assets folder, replacing the VS2003 version.
  5. Unity crashes as soon as the play button was clicked.

All my C++ CLR test projects are causing Unity crashes.

(On a side note, by VS2008 C# CLR Plugins have no problems.)

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
2
Best Answer

Answer by SteveFSP · Jul 18, 2010 at 09:53 PM

This answer applies to Unity 2.6 and Visual Studio 2008

Unlike C#, the default CLR project configuration in Visual Studio is mono-unfriendly. For some details, see the mono-project documentation.

To create a Managed C++ library that is compatible with the free version of Unity, set up its project as follows:

  1. Start Visual Studio 2008.
  2. Select File > New > Project > Other Languages > Visual C++ > Class Library
  3. After project creation, right-click the project and select Properties.
  4. Select Common Properties.
  5. Set the Targeted Framework to .NET Frameworkd 2.0
  6. Set Confuration (at top of tab) to "All Configurations".
  7. Select Configuration Properties > General
  8. Set Common Language Runtime support to Safe.

If you are re-using existing code you may have to refactor it in order to get it to build.

This may not be the only allowed configuration. But any other Common Language Runtime support type will result in a DLL that will crash or cause run-time errors in the Unity editor.

Other Considerations:

If your library will need access to the UnityEngine namespace, you can add it to your project as follows:

  1. Bring up the project properties. (Right-click the project and select Properties.)
  2. Select Common Properties.
  3. Click Add New Reference...
  4. Browse to and add the UnityEngine.DLL. (E.g. Under C:\Program Files\Unity\Editor\Data\lib)
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 jverwey · Oct 18, 2010 at 03:47 PM 0
Share

Is there any way to debug such a $$anonymous$$anaged C++ dll, stepping through the code line by line?

avatar image SteveFSP · Oct 21, 2010 at 11:09 PM 0
Share

Sorry, I'm afraid that I don't know the answer. But if you are talking about debugging via Unity 3.0, then the answer is most likely no.

avatar image
0

Answer by Lantiszhu · Oct 14, 2011 at 08:34 AM

nice!well done!

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 Lantiszhu · Oct 14, 2011 at 08:34 AM

nice! well done!

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 ChiuanWei · Feb 10, 2012 at 07:59 AM

u do a good job, man!

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

2 People are following this question.

avatar image avatar image

Related Questions

Does anyone have figures which show the take-up ratio for new users hitting unity webplayers for the first time? 2 Answers

Audio signal plug-in? 1 Answer

Recompiled plugins not refreshing in Unity 1 Answer

System.Speech 2 Answers

Data is lagging the external device. Why? 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