Guye Incognito
Guye Incognito

Reputation: 2844

How to pass an array from a c++ library to c#

I'm writing a plugin for this c++ physics library for Unity3d. The library is a superset of Box2D with particle simulation added. In the c++ library there is a function that returns an array of 2d vector objects for all the particles. I'm wondering how I could pass this back to Unity so I can draw them? I Cant pass objects between the library and Unity. Could I pass a 2d array of floats? I heard that I should instantiate an array of the correct size in Unity in c#, then pass it to the c++ function where all the data will be filled in, then pass it back to Unity (this is to help avoid memory problems in c++) How would you write this in c++? Alternatively could I use an out paramater to do this? And how would you write that?

Upvotes: 0

Views: 824

Answers (1)

Idov
Idov

Reputation: 5124

You can declare the method in your C# code as returning IntPtr and then convert it to the array you need (an array of the managed version of the objects you have in your C++ code) .

Upvotes: 1

Related Questions