Question by
AzeExMachina · Jan 12, 2018 at 04:33 PM ·
c#plugindllc++
Marshal C# Method with C++
Hi everyone, I want to call a specific method in my Unity project within an external plugin. Here is my C++ code:
static void UNITY_INTERFACE_API OnRenderEventThreadSafe(int eventID)
{
[...] Some C++ code
//Call C# Method here
}
My C++ code does already work on its own but now I want to call a specific Unity method. How can I manage to do this? I tried creating delegates like this
#if UNITY_EDITOR
[DllImport("lib")]
#else
[DllImport ("lib")]
#endif
private static extern void Method(Delegate callback);
private delegate void Delegate(int number);
[MonoPInvokeCallback(typeof(Delegate))]
private static void DelegateMessageReceived(int number)
{
Debug.Log("MessageReceived " + number);
}
public static void Method2()
{
Method(DelegateMessageReceived);
}
But this doesn't seem to work
Comment
Your answer
Follow this Question
Related Questions
Classes that inherit UIBehaviour in a DLL no longer visible in Unity editor. 2 Answers
Is it possible to access rig joints in C#? 0 Answers
Unity crashing with runtime error, when accessing opencv function in unity. [HELP]!!! 1 Answer
Creating multiple instances of a dll object 0 Answers
Cinemachine (or the unity compiler) broken due to some unknown reason 1 Answer