2

I am building a native objective-C plugin in Unity. I have a struct in unity that has the mesh data that I am trying to send to the Objective-C plugin.

My struct looks like this

public struct MeshData
{
    public float[] vertices;
    public int vertexCount;
    public int[] faces;
    public int faceCount;
    public byte[] faceClassifications;
    public float4x4 transformMatrix;
}

I looked into marshaling in C# but my plugin function doesn't get called. There is also no good documentation that explains how to do this.

Another thing I tried was to get and Intptr for the struct and then send it over to the Objective-C side but that approach failed as well.

I am not super experienced with moving pointers and converting memory to pointers in C# and then rebuilding them on the objective-C side.

How should I go about this?

Sarang Borude
  • 329
  • 1
  • 12
  • An answer related to passing struct data to a dll was answered [here](https://stackoverflow.com/questions/43848841/pass-large-arrays-of-structs-from-c-sharp-unity-script-to-c-dll-using-gchandle). Their problem was also solved so it works as an example. – TEEBQNE May 03 '21 at 19:17
  • I don't think the answer is solving my problem, Sorry, I missed adding a very important detail in this, the arrays are variable length arrays so it is not possible to determine the actual size of the struct. – Sarang Borude May 05 '21 at 23:59
  • You will need to pass the size of the arrays as well as a pointer to the first element in the array then. Either something [like this](https://stackoverflow.com/questions/17084272/passing-a-struct-containing-an-int-array-of-unknown-size-from-c-sharp-to-c-and-b) or [like this](https://answers.unity.com/questions/9559/objective-c-plugin-arrays.html). – TEEBQNE May 06 '21 at 19:38

0 Answers0