0
\$\begingroup\$

I'm writing a plugin for unity, I need to send a texture from ios to unity. There is a UnitySendMessage function which takes char* as parameter, but I didn't find a way to convert id<MTLTexture> to char*.

How can I send id<MTLTexture> from ios and receive it in unity?

My current code :

//ios side ...
_texture = CVMetalTextureGetTexture(texture);
UnitySendMessage(CALLBACK_OBJECT, CALLBACK_TEXTURE_READY,_texture);//error
//...

//unity side
private void OnTextureReady(string texture_str)
{
   IntPtr texture = new IntPtr(Int32.Parse(texture_str));
   int width = 256;
   int height = 256;
   rawImage.texture = Texture2D.CreateExternalTexture(width, height, 
   TextureFormat.ARGB32, false, false, texture);
}
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Don't try to cast string to IntPtr. char* is just pointer and any pointer(char*, void*,...) coming from native side unity treat it as IntPtr.

id<MTLTexture> tex = yourTexture;
char* ptr = &tex;

And now you have a ptr from native side

\$\endgroup\$
2
  • \$\begingroup\$ I don't understand what you are saying, It doesn't fix the problem, I still have to convert void* to char*(because UnitySendMessage accept char* as the third parameter) \$\endgroup\$
    – omid
    Commented May 21, 2018 at 7:48
  • \$\begingroup\$ It's doesn't matter I changed my answer I don't understand why try cast string to IntPtr \$\endgroup\$
    – buffalo94
    Commented May 21, 2018 at 8:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .