Accessing Unity console from Native Audio Plugin SDK

Hello,
I just started diving into developing plugins with the Native Audio Plugin SDK. Is there a way to directly access the Unity console from within an audio plugin, so I can print some messages for debugging?

OK, in case anyone is interested, this is what I found. It’s a hacky workaround rather than a solution, though. It works roughly like this:

You can pass a buffer from a Unity Script to a C function:

     [DllImport("AudioPluginDemo", CallingConvention = CallingConvention.Cdecl)]
    private static extern void GetLastError(StringBuilder dest, int n);

    private static void PrintErrorMessages()
    {
        StringBuilder sb = new StringBuilder(256);
        GetLastError(sb, sb.Capacity);
        if(sb.Length !=0) print(sb.ToString());
    }

In the native module, you have to store your messages, and then write them to the passed buffer when the function is called.

extern "C" char * GetLastError(char *dest, size_t n) {

    if(n < YourPlugin::errorMessages.size() || YourPlugin::errorMessages.size() <= 0) return NULL;

    for(int i = 0; i<YourPlugin::errorMessages.size(); i++) {

        dest[i] = YourPlugin::errorMessages[i];

    }
    YourPlugin::errorMessages = "";
    return dest;
}

Then call the C function from within the Unity script and print the return value to the console.

    void Update () {
        PrintErrorMessages();
    }

Further reading: Interop with Native Libraries | Mono

Still appreciating better solutions. :):slight_smile: