- Home /
Returning a Vector3 array from c++ native code
I've got a c++ plugin which calculates a vertex array, and I need to assign it to a mesh in c#. I'm wondering how I might be able to transfer my calculated vertex buffer back into c# managed code.
Do I need to deal with Marshalling, or put c# into unsafe mode? I'm not really following the examples I've seen so far.
I think its better if you do it inside of unity if you can unless its a crazy amount of calculation that absolutely need the speed of c++.
Answer by Kolja_Lubitz · Sep 16, 2021 at 06:52 AM
Hi
you have to create a struct in c++ like this in your cpp.h's extern "C" { } :
typedef struct _VECTOR3
{
float x;
float y;
float z;
} VECTOR3;
Than you can create a method in c++ that accepts an Array of VECTOR3 and can change it.
cpp.h
CPPDLL_API int CreateMesh(VECTOR3* pArray, int size);
cpp.cpp
CPPDLL_API int CreateMesh(VECTOR3* pArray, int size)
{
for (int i = 0; i < size; i++)
{
pArray[i].x += 100;
}
return 0;
}
Your answer
Follow this Question
Related Questions
Passing large Vector array to native plugin without copying 2 Answers
playing a different animation in an array 1 Answer
how can i make the enemy kill more players one after the other chasing them ??? thank you 0 Answers
How do I Resize an Array in JS? 1 Answer
Using a list of arrays to make Unity UI 2D button toggle colors 0 Answers