- Home /
Can I send a message from a plugin into Unity?
I'm writing a Mac bundle plugin, which runs its own thread (is that ok?). I need to have it signal back to Unity sometimes. If only to print a string to the console ('print' is not doing it for me). Is this possible?
$$anonymous$$ulti-threading is fine. Just make sure to not touch the Unity API outside of the main thread (where scripts are normally run). I would stay away from printing a string to console as that might be logged to a file and might reveal information that should not normally be revealed to the end user. You will need to use some intermediary that is thread safe and that can run Unity functions/other stuff for you.
I'm only having to do this because XCode4 doesn't want to run Unity so I can debug my plugin. If I try to attach to a running Unity, it says it's 'running Unity' but then stops saying that. No breakpoints can be set.
Answer by Dreamora · Feb 18, 2012 at 06:56 PM
You can not attach native code debuggers to managed code and unity runs managed or more precisely mixed code.
you can only attach the debugger to players built but even then, you can not set any breakpoints, again as its not native but mixed code. But at least you get a callstack when it crashes which might give you an idea.
To debug code running in unity, use monodevelop and attach the debugger to the unity process or the player process (you need to build the player as development - remote debugging enabled)
I should have mentioned, I'm building this as standalone $$anonymous$$ac (not iOS). I take it UnitySend$$anonymous$$essage is not supported except for iOS? What I'm REALLY looking for is the proper way to initialize a Cocoa class there.
Thats correct. Standalone builds have no way to easily or directly call back into unity at all beside accessing the $$anonymous$$ono layer itself.
Question is if you really need it at all as I don't see how initializing a class is related to call back into Unity as sendmessage can not send them through anyway.
I'm just trying to debug my plugin, and the old examples have it using 'print' to print to the console, which it doesn't. Not having a debugger, the only thing I can think is to essentially Debug.Log all over the place. So my code doesn't work, I need to know, did it initialize, where did it fail, what does it think it's doing, all that.
For debugging the native plugin, you best drop it into another native code shell and test run it there with XCode static analysis and unit test if you want to go all out. Unity has no impact on the behavior of the plugin so this is a very simple solution :)
Your answer
Follow this Question
Related Questions
how do I make a .dll after making a .bundle? 0 Answers
How to debug your Mac bundle(Plugin) for Unity via Xcode 0 Answers
Why doesn't my bundle build for Mac OS X using Xcode 4.5? 1 Answer
iOS build is including Mac OSX .bundle files into Xcode Project 2 Answers
Undefined symbols for Unity Plugin written in C++ when compiled to XCode 0 Answers