Calling a C++ function from C
In unity you would call the function just as you would for any other internal library using PInvoke. The only difference is that you need to use the Native.Invoke
method to call the function.
Well, you don't NEED to but you risk crashing your editor if you don't. Native.Invoke
will properly handle hot-reloading and other edge cases that can cause your editor to crash.
Here is an example of calling a C++ function from C#:
using CppInator.Runtime;
[DllImport("__Internal")]
static extern int PowerFunction(int value, int power);
void Start()
{
int result = Native.Invoke(PowerFunction, 2, 3);
Debug.Log(result); // Output: 8
}
And here is the C++ code that the C# function is calling: