Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you reset or reimport, plugins, in Unity / Mac?

Get a Unity project with a native low-level plugin .. Mac version.

enter image description here

Make a small change in the Xcode plugin project, and build.

You now have the new plugin library in the Unity project.

If you "Build" again, the final Mac app of course now contains the new library - no problem.

However .....

if you hit Play in the Editor,

it does not pick up the change in the library.

In fact it seems:

Every time you change a library in Unity, you must restart Unity!

Everything has been tried, "Reimport all assets", AssetDatabase.Refresh, renaming, etc etc. It seems you literally must restart Unity.

What's the deal on this?


More information on this:

It would seem that mac shared libraries/bundles cannot be unloaded. Article:

https://docstore.mik.ua/orelly/unix3/mac/ch05_03.htm

Apparently this was fixed in 10.5:

https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/dlclose.3.html

Maybe Unity could solve this now. At their usual pace it should happen anytime around 2035.

like image 647
Fattie Avatar asked Mar 04 '23 19:03

Fattie


1 Answers

Sadly it comes down to you can't do anything about it.

As per .net's DLL handling DLL's cannot be unloaded individually without closing the application domain. And while Unity picks up the changes done to the DLL the old version is kept in memory and used at runtime in the editor. A "funny" thing you can do to see this in action is by deleting the native plugin from within the editor. Confirm that you want to delete the file. The file will dissapear from the inspector. However if you right click the folder and refresh (ctrl+r) you will see that the file gets reconstructed (this also happens when hitting "re-import all", as the application domain isn't closed, despite unity restarting).

When building the application it will however use the locally stored file, and not the memory stored file. Hence the plugin being updated on the build.

There is no way to unload an individual assembly without unloading all of the application domains that contain it. Even if the assembly goes out of scope, the actual assembly file will remain loaded until all application domains that contain it are unloaded.

source

This has been a problem for some time now, and people have made attempts for work arounds and/or fixes, but as far as I am aware the "work arounds" that exist now are for windows only. here are some links to discussions about it.

  • "Unload a plugin"
  • "Reloading native plugins"

I suppose something that could be done is writing a wrapper that automatically restarts Unity when the dll has been edited... Although this won't solve the issue it'll atleast make it somewhat less of a hassle.

like image 96
Remy Avatar answered Mar 09 '23 05:03

Remy