0
\$\begingroup\$

I'm trying to get GL.IssuePluginEvent to work, according to this: http://docs.unity3d.com/Manual/NativePluginInterface.html

I have a plugin made with this code:

extern "C"
{
    void UnityRenderEvent (int eventID)
    {
        NSLog(@"Got render event.");
    }
}

I can call that function directly from Unity, and it works; I'm sure I've built the plugin correctly, and included it in the project correctly. But when I do GL.IssuePluginEvent(0), nothing happens. Some idea what I could be doing wrong? According to Unity's demo, this is all that has to be done. I think.

I know that in their example, they have it defined as void EXPORT_API, but I found this in their code example:

// Attribute to make function be exported from a plugin
#if UNITY_METRO
#define EXPORT_API __declspec(dllexport) __stdcall
#elif UNITY_WIN
#define EXPORT_API __declspec(dllexport)
#else
#define EXPORT_API
#endif

So on iOS, EXPORT_API becomes "".

\$\endgroup\$

2 Answers 2

0
\$\begingroup\$

From Unity 4.5, you have to register the event.

"iOS: Added support for render events (GL.IssuePluginEvent). Please note that you need to manually register them, as iOS do not support dynamic libraries. Check trampoline for UnityRegisterRenderingPlugin function."

For example:

#import <UIKit/UIKit.h>
#import "UnityAppController.h"

extern "C" void UnitySetGraphicsDevice(void* device, int deviceType, int eventType);
extern "C" void UnityRenderEvent(int marker);

@interface MyAppController : UnityAppController
{
}
- (void)shouldAttachRenderDelegate;
@end

@implementation MyAppController

- (void)shouldAttachRenderDelegate;
{
    UnityRegisterRenderingPlugin(&UnitySetGraphicsDevice, &UnityRenderEvent);
}
@end

So you just have to do some editing of UnityAppController.mm after you build the project. If you do "Append" it will leave your edits in place.

\$\endgroup\$
0
\$\begingroup\$

This is a comment, but I don't have enough rep on this site (though I do on stack exchange). Re: Almo's answer, there's a bit of a bug (at least for me) in the whole plugin setup in that if you have more than one plugin, and they both implement UnityRenderEvent, XCode seemed to resolve my callback to the other plugin's function. Mine never got called.

On one hand, this made sense, all the functions are compiled statically and linked and have unmangled C names, so I can easily see how it can jump to the wrong one... BUT, I would have expected a multiple-symbol link error, and never got one.

My solution to this was just to have a different function name for IOS and call that above. But hopefully this might help someone...

\$\endgroup\$

You must log in to answer this question.

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