32bit and 64 bit plugin environment


I’m working on a Unity plugin. Since the editor is 32bit I need the plugin to be 32 bit. However for the final application we are making the assets are so big that we need to build the project and plugin for 64bit. How do developers usually create an environment where 32 and 64bit dll’s can coexist in Unity?

What we’ve found so far is the you can import both dll’s and use IntPtr.Size to distinguish between the architectures and invoke the correct dll, but that’s not exactly pretty nor efficient. What we would like is something along the lines of

    [DllImport ("Plugin64")] ...
    [DllImport ("Plugin32")] ...

so we can choose which to use at compile time. Does Unity or C# support something like this? We’ve tried _WIN64 and WIN64, but those aren’t defined.

Another solution we’ve found that works but isn’t pretty is to simply swap the dll’s after the project’s been build, but this irks us just as much and isn’t exactly a great solution since it requires manual work from the developer each build. (Yes we cold setup a build script and we have, but we would still have to remember to do it for each new project and we all know how forgetful developers are… :))

Hoping someone has a better solution.


Unity 5 brings new defines, see here.

Unity 5 will have UNITY_64 and
UNITY_32 defines for standalones, as
well as UNITY_EDITOR_64 and _32.