mcpiroman / UnityNativeTool

Allows to unload native plugins in Unity3d editor
MIT License
183 stars 18 forks source link

DLLs are not unloaded when changed path pattern #7

Closed Calandiel closed 4 years ago

Calandiel commented 4 years ago

I'm not sure why. I have a game object with the dll manipulator script set to preload mode. Having added some logs in DllManipulator it seems like all functions are loaded and unloaded correctly. And yet, I can't replace the dll with a new version without closing unity first. Did I misunderstand the purpose of this repository?

mcpiroman commented 4 years ago

Indeed, you really should be able to edit it.

To solve this I'll need to know your setup. In particular about the names because this should be the important factor here. My first guesses are:

  1. Are your DLLs named correctly (this is, if you haven't changed the pattern setting, it should have at the beginning of file name, so e.g. `Assets/Plugins/MyDll.dll`).
  2. In [DllImport], do you specify DLLs like you normally would? (This is MyDll or MyDll.dll but not __MyDll)
Calandiel commented 4 years ago

I changed the pattern from {assets}/Plugins/__{name}.dll to {assets}/Plugins/{name}.dll I added logs inside DllManipulator.cs in LoadAll(), inside the innermost foreach loop. It logs names of my dlls functions correctly, so I assumed it found it just fine. My dll is called mmo_client.dll and my dll imports are simply [DllImport("mmo_client")]

Could the fact that my dll is blocking a file and a socket after the game is closed cause any issues?

mcpiroman commented 4 years ago

You see, the straight {assets}/Plugins/{name}.dll pattern is unfortunately not allowed because this is what Unity excepts, so it loads the plugin when it has the opportunity to do so, even though it won't actually use it. This is why I have to bother with these underscores. I guess I should have documented this.

So if you change it back to default (or anything other than current one) and also change the file names of DLLs accordingly it should work then. For the release build you'll have to remember to change the files back to normal though (so Unity can use them in the usual way). I can't really help here but I guess its not so bad.

Calandiel commented 4 years ago

Oh, I see. That explains a lot. Thanks ^ . ^