forrestthewoods / fts_unity_native_plugin_reloader

Single-file helper to allow Unity NativePlugins to be updated without restarting the editor.
Other
106 stars 16 forks source link

Support for rendering extensions #3

Open pezcode opened 5 years ago

pezcode commented 5 years ago

NativePluginLoader doesn't seem to work for loading native rendering extensions. DLL loading etc. works fine but OnGraphicsDeviceEvent is never called.

I don't know enough about Unity internals to know why DllImport works and loading the DLL dynamically doesn't, I assume it gives Unity enough metadata for reflection to realize that the script is loading a plugin and registers the callbacks.

Is this something you've tried?

Nyran commented 3 years ago

Hi,

I can confirm the behaviour that @pezcode described. I also tried out loading all functions with the great auto loader functionality, but the rendering function can not be properly loaded.

I assume it may has something to do with the return type of the rendering event functions (UnityRenderingEvent) which is exposed with DLLImport on the C# side as an IntPtr.

extern "C" UnityRenderingEvent UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API GetRenderEventFunc() { return OnRenderEvent; }

UnityRenderingEvent itself is a function pointer to a function with return type void and an int parameter.

Did anyone investigate further on this since the issue was first sighted and has some insight on that?

Thank you very much!

EDIT: I checked the flow of the function, and in fact, the functions are all called. I suspect that the problem is coming from Unity utilizing another thread for enqueuing the rendering events, and that the graphics API can not be created, which is why the function just returns unsuccessfully.