Tool created mainly to solve the old problem with reloading native plugins without the need to reopen Unity Editor.
[DllImport]
.UnityPluginLoad
and UnityPluginUnload
do fire - to enable them see this section.Either download and add unity package from releases, or clone this repo into the assets
of your project.
<Project Root>/Packages
folder to use it as a local embedded package with upm.In project settings, set Api Compatibility Level to .NET 4.x or above. Edit > Project Settings > Player > Other Settings > Api Compatibility Level
Check Allow 'unsafe' code. Edit > Project Settings > Player > Other Settings > Allow 'unsafe' code
One of the gameobjects in the scene needs to have DllManipulatorScript
on it. (This script calls DontDestroayOnLoad(gameObject)
and deletes itself when a duplicate is found in order to behave nicely when switching scenes).
__
(two underscores) at the beginning of your dll files in the Assets/Plugins folder (e.g. on Windows, plugin named FastCalcs
should be at path Assets\Plugins\__FastCalcs.dll
).extern
methods in the main scripts assembly will be mocked (i.e. handled by this tool instead of Unity, allowing them to be unloaded). You can change this in options and use provided attributes to specify that yourself (they are in UnityNativeTool
namespace, file Attributes.cs
).DllManipulatorScript
editor or window.Alt+D
and Alt+Shfit+D
respectively. Editable in the Shortcut Manager for 2019.1+[NativeDllLoadedTrigger]
. See Attributes.cs
.For that, you'll need a StubLluiPlugin
DLL. I only embed it into .unitypackage for x64 Windows platform, so for other cases you'll need to compile it manually.
This is, compile the file ./stubLluiPlugin.c
into the dynamic library (name it StubLluiPlugin
, no underscores) and put into Unity like you would do with other plugins.
UnityRenderingExtEvent
and UnityRenderingExtQuery
do not fire.extern
methods (such as [MarshalAs]
or [In]
) are supported.MarshalCookie
, MarshalType
, MarshalTypeRef
and SafeArrayUserDefinedSubType
on [MarshalAs]
attribute are not supported (due to Mono bug).UnmanagedType.LPArray
in [MarshalAs]
is not supported (due to another Mono bug). Note that this should be the default for array types, so in trivial situations you don't need to use it anyway.ExactSpelling
and PreserveSig
of [DllImport]
attribute are not supported.OnApplicationQuit
event are not-very-well handled (usually not something to worry about).DLL path pattern
option cannot be simply set to {assets}/Plugins/{name}.dll
as it would interfere with Unity's plugin loading - hence the underscores.2019.3.x
Unity changed behaviour of building. If you want to use this tool in the built game (although preferably just for development) you should store your plugins in architecture-specific subfolders and update the DLL path pattern
option accordingly, e.g. {assets}/Plugins/x86_64/__{name}.dll
.UnityNativeTool.DllManipulatorScript
script by default has an execution order of -10000 to make it run first. If you have a script that has even lower execution order and that scripts calls a DLL, then you should make sure that UnityNativeTool.DllManipulatorScript
runs before it, e.g. by further lowering its execution order.Configuration | Relative call time |
---|---|
Vanilla Unity | 100% |
Preloaded mode | ~150% |
Lazy mode | ~190% |
With thread safety | ~430% |