Plug-ins for desktop platforms are libraries of native code written in C, C++ and Objective C. This page describes plug-insA set of code created outside of Unity that creates functionality in Unity. There are two kinds of plug-ins you can use in Unity: Managed plug-ins (managed .NET assemblies created with tools like Visual Studio) and Native plug-ins (platform-specific native code libraries). More info
See in Glossary for Windows, macOS and Linux. For further information see documentation on Native plug-insA platform-specific native code library that is created outside of Unity for use in Unity. Allows you can access features like OS calls and third-party code libraries that would otherwise not be available to Unity. More info
See in Glossary.
You can deploy macOS plug-ins as bundles or, if you are using IL2CPPA Unity-developed scripting back-end which you can use as an alternative to Mono when building projects for some platforms. More info
See in Glossary, loose C++ files which you can use [DllImport(“__Internal”)] syntax to invoke. For further information on loose C++ plug-ins see documentation on C++ source code plugins for IL2CPP.
To create the bundle project with XCode, open XCode 11 and select File > New > ProjectIn Unity, you use a project to design and develop a game. A project stores all of the files that are related to a game, such as the asset and Scene files. More info
See in Glossary, then navigate to macOS > Framework & Library > Bundle. For more information on working with XCode see Apple’s documentation on XCode.
You must build your plug-in as a universal binary that contains 64-bit architectures. Alternatively, you can provide separate dylib files. If you are using C++ (.cpp) or Objective-C (.mm) to implement the plug-in then you must make sure you declare the functions with C linkage to avoid name mangling issues.
extern "C"
{
float FooPluginFunction ();
}
Plug-ins on Windows are either .dll files with exported functions, or loose C++ files if you are using IL2CPP. You can use most languages and development environments that can create .dll files to create plug-ins. You must declare any C++ functions with C linkage to avoid name mangling issues.
Plug-ins on Linux are .so files with exported functions. While these libraries are typically in C or C++, you can use any language. As with the other platforms, you must declare any C++ functions with C linkage to avoid name mangling issues.
In Unity, the Plugin Inspector manages your plug-ins. To access the Plugin InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary, select a plug-in file in the Project windowA window that shows the contents of your Assets
folder (Project tab) More info
See in Glossary. For Standalone platforms you can choose the CPU architecture with which the library is compatible. For cross platform plug-ins you must include the .bundle file (for macOS), the .dll file(for Windows), and the .so file (for Linux). Unity automatically picks the right plug-in for the target platform and includes it with the player. For further information see documentation on the Plugin Inspector.
Once you have built the bundle, you must place it in the AssetsAny media or data that can be used in your game or project. An asset may come from a file created outside of Unity, such as a 3D Model, an audio file or an image. You can also create some asset types in Unity, such as an Animator Controller, an Audio Mixer or a Render Texture. More info
See in Glossary folder (or the appropriate architecture-specific sub-directory) in your Unity Project. Unity then finds it by name when you define a function like the following in the C# script:
[DllImport ("PluginName")]
private static extern float FooPluginFunction ();
Note: PluginName
should not include the library prefix nor file extension. For example, the actual name of the plug-in file would be PluginName.dll on Windows and libPluginName.so on Linux.
Project | Description | Link |
---|---|---|
Simplest Plugin Example | This project implements basic operations such as; print a number, print a string, add two floats and add two integers. | Follow the link to the Unity GitHub repository to download the Simplest Plugin Example project. This project includes Windows, macOS and Linux project files. |
Native Renderer Plugin | This is an example of a low-level rendering plugin. This project demonstrates the following: - Renders a rotating triangle from C++ code after all regular rendering is done. - Fills a procedural texture from C++ code, using Texture.GetNativeTexturePtr to access it. |
Follow the link provided to the Unity GitHub repository to download the Native Renderer Plugin. This project includes Windows, UWP, macOS, WebGL and Android files. |
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.