Juce unity audio plugin communication

Hey folks,

I’m trying to build a toy synth in unity using a juce plugin. Generally I’ve got the plugin running so I can call my juce library from my game objects with no problem.

However I’m trying to call some custom functions from my CustomAudioProcessor.cs from my unity scripts. This works if I set up my extern interfaces on the generated juce_UnityWrapper.cpp but in that class the plugin instance is set of type AudioProcessor. Do I need to change that to my CustomAudioProcessor so I can access my public functions? I’m not sure if that’s the intended way of accessing them.

Sorry for the nooby question!

Apologies if my question was a bit confusing! Let me try to explain what I’m trying to accomplish.

Basically I’ve got the Unity game running my JUCE synth plugin from the unity audio mixer and I’m able to control my synth parameters at runtime from my gameobject scripts which is great!

However I would also like to load a sample from unity into my juce plugin. Usually I would do this through the plugin editor if this was a VST and pass that sample into my audio processor. I have my plugin editor disabled for this unity plugin so I need to find a way to directly upload that sample into my plugin. Anyone had any experience doing something similar?

I can see the generated juce_Unity_Wrapper.cpp already has implementations of the extern interface functions (like process callback etc which calls the processBlock on the audio processor) but if I define let’s say a new extern load_sample(float* data), on the implementation side (juce_Unity_Wrapper.cpp) I see no way of accessing my audio processor subclass from the pluginInstance (pluginInstance->loadSample(data)) because the pluginInstance is defined as a AudioProcessor object.

Thanks in advance!

Im also attempting to do something similar. Did you find a way to get at the JUCE functions via the wrapper?

Hey, unfortunately I haven’t managed to do it yet with the JUCE unity plugin export. Instead I temporarily mirrored some of the DSP functionality I needed in Unity and doing the audio processing with OnAudioFilterRead which works fine now but it’s not a good practice as it can cause audio drops due to the garbage collection. I’m planning to get back to it soon though, it would be great if someone else has done something similar and get some hints on how to do so. Would be awesome to be able to use all the JUCE goodies in Unity! :slight_smile:

Hey everyone,

check out this little tutorial I wrote a while back:

This is definitely not the ideal way to do things, since it involves doctoring some juce files, but it certainly is a start and it works :slight_smile: This will expose juce functions to unity and let you call them from within your unity code


Just as a side note as I notices this while scanning over the topic: Changes getting overwritten are no real issue if you are using git.

Having your own fork of JUCE and modifying it makes it super easy to pull recent JUCE updates into your fork without breaking your customisations. Furthermore, you are more likely to notice if your changes clash with some changes in the upstream JUCE repository.
We do this quite successfully for some longer time now and I have seen other companies here with their own forks as well…

yes that’s obviously true and I’ve already changed this paragraph in the actual gist… no idea why the preview on here shows an old version… I’m having my own fork as well…

The point still stands that this can probably also be accomplished without doctoring around in the juce files, that’s all I was saying with that :slight_smile:

//edit removed and re-added the link, now it shows the updated version :slight_smile:

1 Like


Thanks very much for adding so much detail, it would take me ages to figure this out. Going through the notes it looks like an elegant solution to my problem!

I will try it this week and report back :slight_smile:

Just wanted to let you know that your method worked great after all! Thanks so much for sharing :slight_smile:

This brilliant. Its something I’ve been looking for for a while. I have one problem that maybe you can help me with.


is throwing an error because createPluginFilter outputs an AudioProcessor…

I think I’m doing something wrong at the pointer…

 std::unique_ptr<MyAudioProcessor> pluginInstance;

Sorry if I’m being a bit dumb.