- Home /
How can the native Unity plugin be initialized before the Direct3D rendering device is created?
I'm writing a plugin and I need to call NvAPI_Stereo_SetDriverMode. According to the NVAPI documentation, this needs to happen before the Direct3D 9 or 11 device is created.
The soonest I could call this function is when the plugin is loaded, but I do not know when or on which thread this occurs - this isn't documented. The kGfxDeviceEventInitialize event is called after the device is created, so that is too late.
If the plugin could issue its own create / destroy device events, that might solve my problem, but I don't think this is possible.
Has anyone come across this issue and know how I can solve it?
Answer by Christian Refvik · Jul 10, 2013 at 05:58 PM
I've tried the following approaches and nothing seems to work:
I've verified all of these approaches are being called, but none of them are early enough. If anyone has any insight into this, please let me know. I'm trying to get NVIDIA 3D vision to work in direct mode. I've searched the forums and answers for this and based on the answers and examples I've seen, no one currently has this working.
If Unity could to add a pre-initialize device event, then this would work.
Okay, I contacted Unity3D support and they said the following:
Unfortunately it is not possible to send events to your plugin before the graphics device is initialized.
I certainly wish they had this feature. I need to do some NVIDIA driver initialization before the device is created. I also tried to use a wrapper application to do the initialization before Unity starts (ie. using spawn, fork/exec, and CreateProcess), but that doesn't work either.
Answer by PMY Archon · Oct 22, 2013 at 12:27 PM
If you're creating a Standalone build, you can write a simple DLL and a launcher.
Launcher will CreateProcess() of standalone executable file with CREATE_SUSPENDED flag set.
Then you can inject your DLL with a call to NvAPI_Stereo_SetDriverMode() from DLL_PROCESS_ATTACH section.
P.S. Don't forget to call ResumeThread() after you finish injection.
Your answer
![](https://koobas.hobune.stream/wayback/20220613105436im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to access an Android native plugin in unity ? 0 Answers
Passing large Vector array to native plugin without copying 2 Answers
Different approaches to Android plugins 0 Answers
U3DXTException: in SocialXT.Share 0 Answers
Encrypt native plugins/protect IP 0 Answers