I’m trying to figure out what the correct, or “best”, solution to this problem is.
I have a package I am developing. It includes some native C++ libraries (DLLs on Windows). The package provides some custom EditorWindows for the various utilities the package provides. In a number of cases, some or all of the native plugins are loaded as a result of some of these EditorWindows being opened, which for a user can often be “when Unity launches”. So even without entering Play mode in their game, Editor scripts have referenced the plugins as potentially as early as opening the project.
Now the plugins are locked. they won’t be unloaded by Unity until Unity is exited. On Windows in particular the DLLs themselves can’t be deleted or overwritten while Unity is running.
So if, while the user has a Unity session running, how are they supposed to update or delete the package in the Package Manager? The common advice of “restart Unity” doesn’t seem to apply because once the Editor relaunches, the DLLs are immediately loaded again. I can only think of a couple “solutions”:
-
Tell the user to exit Unity, and then navigate to where the package is installed in Windows Explorer or Finder or whatever, and delete it entirely before re-opening the project in Unity. This is extremely ugly and unprofessional design. Absolute no-go.
-
Modify package code so that the plugins are not auto-loaded simply by opening the project. This is potentially workable. There would need to be some sort of “line in the sand” that’s conveyed to the user as they begin using the tools, something like “once you click this button, the package can’t be modified without restarting Unity!”. This is quite inelegant.
And, even without my “special case” of having the plugins auto-loaded by the editor, there should still be a general solution to managing packages that use plugins. A developer deliberately managing their own plugins accepts the burden of needing to restart the editor from time to time, but a developer that’s using a third party Package which uses its own plugins may not appreciate the experience, and that is potentially a lost customer. Has anyone come up with a more creative/elegant answer?