- Home /
Possible to pass Unity classes to plugin directly?
Hey there,
I am currently passing a captured screenshot to a plugin by converting a Color32[] to a byte[] which is then "converted" to an IntPtr and passed to the plugin function.
While this does work, I wonder if there is any way of passing data from C# to a plugin without doing so many conversions and still be able to do use the data in C++. That would increase performance a lot.
Maybe this is more of a C# than a Unity question, but since I'm not a pro at either, I thought I might ask here :)
Have you checked out the Texture Plugin Demo? http://unity3d.com/support/resources/example-projects/texture-plugins
The C++ source isn't included, but they pass an IntPtr to a Color[] directly to the DLL function.
Hmm, the way it looks it must be possible to access that class/struct of 4 float values directly. $$anonymous$$aybe you can treat the pointer you get in C++ as any custom struct that also has 4 float values.
In pure C++ that would be easily possible, I just wasn't sure it would also work when passing data from C# to C++. But thanks, that kind of reassured me ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220613061852im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Segfault in native plugin code, only with Unity 0 Answers
Convert Texture2D to Image emgu CV - fast way 2 Answers
How should a Unity web application gracefully exit? 1 Answer
Plugin running out of memory 0 Answers
Need help with a menu and with plugin 0 Answers