{"id":17987406,"url":"https://github.com/offchan42/unitycppclassdllexample","last_synced_at":"2025-03-25T22:32:05.433Z","repository":{"id":108171608,"uuid":"149588510","full_name":"offchan42/UnityCPPClassDLLExample","owner":"offchan42","description":":bulb: Example exporting CPP class as DLL and importing in Unity C# as native plugin","archived":false,"fork":false,"pushed_at":"2020-10-10T09:37:03.000Z","size":30463,"stargazers_count":13,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-20T21:15:08.053Z","etag":null,"topics":["cpp","csharp","dll","exporting-cpp","native-plugin","unity"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/offchan42.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2018-09-20T09:55:52.000Z","updated_at":"2024-03-17T20:14:39.000Z","dependencies_parsed_at":"2023-04-18T03:04:19.800Z","dependency_job_id":null,"html_url":"https://github.com/offchan42/UnityCPPClassDLLExample","commit_stats":null,"previous_names":["offchan42/unitycppclassdllexample"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/offchan42%2FUnityCPPClassDLLExample","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/offchan42%2FUnityCPPClassDLLExample/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/offchan42%2FUnityCPPClassDLLExample/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/offchan42%2FUnityCPPClassDLLExample/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/offchan42","download_url":"https://codeload.github.com/offchan42/UnityCPPClassDLLExample/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245555040,"owners_count":20634666,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","csharp","dll","exporting-cpp","native-plugin","unity"],"created_at":"2024-10-29T19:08:44.610Z","updated_at":"2025-03-25T22:32:00.415Z","avatar_url":"https://github.com/offchan42.png","language":"C++","readme":"# UnityCPPClassDLLExample\n\nExample exporting CPP class as DLL and importing in Unity C# as native plugin\n\nThere will be times when you want to run your C++ code inside Unity. So you will need to export the code into DLL format and then import it in Unity. This project is showing you an example of exporting a **Student** class written in C++, and import it in Unity C#.\n\n## How to run NOW\n\nOpen Unity project `TestImportCPPClass` and press Play button or Ctrl+P. You will see the output is being printed in the console.\n\n![unity-output-console](img/42227750_2707342812616539_2434765356070338560_n.jpg)\n\nThen take a look at [TestImportCPPClass/Assets/TestImportCPPClass.cs](TestImportCPPClass/Assets/TestImportCPPClass.cs) to see how it is implemented.\nYou will see quickly that it's just a bunch of function calls to the DLL files.\n\n## How to reproduce result from scratch\n\n1. Open Visual Studio 2017 and create a new DLL project.\n2. Copy content of file `TestExportCPPClass.cpp` from `TestExportCPPClass/TestExportCPPClass/` directory.\n\n    ![TestExportCPPClass.cpp](img/42151255_2707336245950529_6861876400492642304_n.jpg)\n3. Go to Build -\u003e Build solution, make sure the build is set to x64 to get a\n    `dll` file ready for Unity project with x64 architecture.\n    (Optional: You could also build x86 version too)\n\n    ![dll-directory](img/42155105_2707337372617083_389608986069958656_n.jpg)\n4. Create a new Unity project.\n5. Copy `dll` file from `TestExportCPPClass/x64/Debug` into Unity's `Assets/Plugins/x86_64` directory.\n6. Open Unity project and copy the C# script from `TestImportCPPClass/Assets/` directory.\n\n    ![TestImportCPPClass.cs](img/42130597_2707341709283316_2299262612510081024_n.jpg)\n7. Create an empty GameObject in the scene and attach the script to it.\n\n    ![unity-hierarchy](img/41949974_2707346379282849_3289350954758963200_n.jpg)\n8. Press Play button to see the output in the console.\n\n    ![unity-output-console](img/42227750_2707342812616539_2434765356070338560_n.jpg)\n\n## Related resources\n\n\u003chttps://stackoverflow.com/questions/315051/using-a-class-defined-in-a-c-dll-in-c-sharp-code/315064#315064\u003e\n\n\u003chttps://github.com/wm4n/unity-cpp-lib\u003e\n\n\u003chttps://github.com/Meach/UnitySimpleNativeLibrary\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foffchan42%2Funitycppclassdllexample","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foffchan42%2Funitycppclassdllexample","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foffchan42%2Funitycppclassdllexample/lists"}