Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
6
Question by cbaltzer · Aug 16, 2013 at 03:21 PM · editorpluginnative plugindelegateos x

OS X Native plugin callback functions

I've written a small iOS plugin, and am trying to make an OS X port. In particular, the plugin is for an augmented reality application, so it uses the webcam. Having to build to a device every time I want to test something is slow, so I want to make a version that works in the editor as well (similar to Vuforia).

Since OS X/Desktop doesn't support UnitySendMessage I've been trying to write a simple callback function to replace it.

My native code:

 // .h 
 extern "C" {
     typedef void (*callbackFunc)(const char *);
 }
 static callbackFunc cameraFrameCallback;
     
 // .mm 
 extern "C" {
     
     void _initWithCamera(const char * camera, GLuint texID, GLfloat width, GLfloat height, callbackFunc callback) {
       
         // some other init here
     
         cameraFrameCallback = callback;
         if (cameraFrameCallback != NULL) {
            cameraFrameCallback([@"IS THIS PRINTING?" UTF8String]);
         }
     }
 
 }


C# code:

 public delegate void cameraFrameCallback(string message);
 
 [MonoPInvokeCallback(typeof(cameraFrameCallback))]
 public static void PrintLog(string message) {
     Debug.Log(message);
 }
 
 [DllImport("DesktopWrapper")]
 private static extern void _initWithCamera(string camera, int texID, float width, float height, cameraFrameCallback callback);
 
 public static void InitWithCamera(string camera, int texID, float width, float height) { 
     if (Application.platform == RuntimePlatform.OSXEditor) {
         _initWithCamera(camera, texID, width, height, PrintLog);
     }
 }


When I call the init method, I would expect the callback to get registered then send back the call to PrintLog, which would print my message in the Unity console. However, when I run this, I get nothing back. My plugin is actually running though, because I'm getting camera frames back as I would expect, just the callback function isn't firing.

Am I missing something obvious, or does this just not work in the Editor?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by cbaltzer · Sep 03, 2013 at 01:03 PM

For people from the future/Google:

The issue was that the Editor doesn't reload plugins until you restart it. The code above actually works fine, but replacing my bundle with new versions when I made changes doesn't actually cause the plugin to get reloaded, you need to replace the bundle then restart the editor.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Jan 10, 2019 at 08:04 PM 1
Share

Thanks for the great code example, @cbaltzer !

(Yes, it is infuriating that you have to restart the editor:

https://stackoverflow.com/a/54018091/294884

)

Cheers....

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GL.IssuePluginEvent with multiple plugins 1 Answer

How to access an Android native plugin in unity ? 0 Answers

Referencing a DLL in C# 0 Answers

Unity iOS - function pointers 1 Answer

DllNotFound when the plugin c++ dll links another c++ dll 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges