mcpiroman / UnityNativeTool

Allows to unload native plugins in Unity3d editor
MIT License
184 stars 19 forks source link

DLL invocation in constructor doesn't work #1

Closed ghost closed 5 years ago

ghost commented 5 years ago

It seems as the original dll is still in use and the "CallingMethodTranspiler" is not working. setup: ` [MockNativeDeclarations] [MockNativeCalls] class RustMesh { public RustMesh() { create_mesh(); } [DllImport("hello")] private static extern IntPtr create_mesh(); }

public class RustBehaviour : MonoBehaviour { void Start() { var rustMesh = new RustMesh(); } } `

hello.dll is next to the RustBehaviour .cs

I've added some log to the DllManipulator and loading seems to be ok.

I've tried to add a different path for hello.dll and it is really unloaded and reloaded the functions, but calling any function still calls the original dll

Any hint?

mcpiroman commented 5 years ago

What's the path of your dll? If you go to DllManipulator script you should see the exact path of the loaded dll file. If it's indeed the same as you expect, then yes, it should work. Also check if there are any errors in the log.

It this doesn't help, you can send me an example project to let check it on my computer.

Also, how do you know that the original dll is called? Becouse if it is locked by editor, then it might be that you have used it at least once via editor and thus it is still locked.

EDIT: The issue seems to be that GetRuntimeMethods doesn't return constructors and other special methots. Fixed build should be available tomorrow.

ghost commented 5 years ago

Thanks I've just figured out, it is the ctor :) Moving the code from ctor into a function makes the code work.

mcpiroman commented 5 years ago

Constructors are now supported in recent release. Closing issue.