Unity Native plugin support (as detailed here is an awesome feature! Thank you JUCE team!!
Currently though, it’s only supported on Desktop Standalone builds with Unity. Would be awesome to be able to seamlessly build Mobile games with Unity using Juce as an integrated audio backend.
+1 on that!
Mobile games is huge, and not being able to use Juce Plugins for mobile, means I can’t use it on a lot projects! Especially with Apple Arcade being the big money giver right now, most indie game deves are targeting mobile too.
In the next 3 months I am working on this to see what actually needs to happen. So Helm being brought up is a good point, it’s not majic just a bunch of boiler plate things that need to be hooked up.
I can imagine if JUCE could get this into the build system, more users might come to JUCE since Android is getting more mature after 100 years of dev.
I’m interested, if you can keep me posted I’d like to use juce in a mobile unity game. The Helm guy is super nice and responsive, worked through some iOS bugs with him.
I do Unity/Plugin as well(for some time), so that is on my radar.
Matt, yeah I agree but I need to figure this stuff out. I have been playing with JUCE for years, but now it’s time I get some of my Android apps ported to a new runtime and I have a audio visualizer in Unity I want a custom sequencer/synth engine for.
Having read the Unity docs and experimented with DSP in C++ using their API, I am pretty sure I will be able to pull something together. The more complicated part is getting the Android stream setup.
In other words, I am going to do it blind, the way I have done other things, then see what it looks like.
Just to reply to myself here, but for anyone that wants to get JUCE in iOS I figured some steps to make it possible. Essentially you need to compile your App Source alongside the JUCE modules with the Unity Wrapper… It’s a bit of a jump around, but here are some basic steps outlining what I did. I’ve tested using the GainPlugin example and all seems to be working well I’m happy to say
Create your plugin with a name like “audioplugin_MyPlugin”.
Create a MacOSx exporter of your plugin.
Within XCode duplicate the static library (.a file) and rename it so it includes iOS at the end, or anything to differentiate it from the other library.
Select the library and then go to Build Phases and add the “include_juce_audio_plugin_client_Unity.cpp” to your compile sources.
Then build the static library. Make sure you select the correct build configuration so you build the iOS one and not the MacOSx one.
Drag and drop your static library plugin into your Unity projects “Plugins/iOS” folder
Click on the plugin and within the inspector select the following frameworks which JUCE depends on: Accelerate, CoreImage and MobileCoreServices
Create a file “MyPluginAppController.mm” within the “Plugins/iOS” folder
Within “MyPluginAppController.mm” we need to override the UnityAppController.mm preStartUnity function to include the Audio Plugin registration. To do this we add the following code:
Then set your player build settings to be iOS and generate the Unity iOS XCode project by clicking “Build”
Select your .app target and set your app signing credentials.
Build your unity app for iOS
It’s quite a number of extra steps and I think key is the fact there is some extra work to be done to load the plugin correctly into the iOS project genrated by Unity (the preStartUnity stuff)… I think some thought needs to be given when you want to load multiple plugins. That will be my next task.
Also, in order to control the parameters from Unity, you’ll need to create a regular MacOSx plugin .bundle. Within it is the C# control script that you can use to expose parameters in the plugin to be controlled from script.
These steps did eventually work for me, but just to elaborate and make some of the steps more clear:
means to open the project settings, select the Shared Code target, and duplicate that (not the .a file itself).
make sure under target SDK you set it to iOS instead of Mac, then proceed to step 4.
Probably should be obvious, but if your plugin uses MIDI then you also need to enable CoreMIDI.
Somewhat tangentially related, if you are building a dynamic library instead of an audio plugin (in my case, I wrote a lib just for managing midi devices separate from the audio plugin), you need to build it as a .dylib for mac.
For iOS: change the project settings in Projucer from a dynamic library to a static library.
Edit the project settings and under the target make sure the SDK is set to iOS instead of mac.
That will build a .a file instead of a .dylib.
In Unity, after checking the the required frameworks mentioned in step 7, also check the box “Add to Embedded Binaries”. I only needed to do this for the lib. Not for the audio plugin for some reason.
When you build, make sure in XCode you always set the build output to target “Any Device” not “My Mac”.
The unfortunate part about these steps is you will have to repeat them every time you save the project in Projucer.
Hi just circling back on this thread, as it seems Xcode no longer lets you add compile sources in Build Phases (per step 4 of @tonetech excellent reply)…
Not sure if this has moved in Xcode or is deprecated (I’m using v 13.4).
@VonWeasel were you able to get a Juce Plugin in a Unity project working on iOS from a recent version of Xcode?
I’m also getting errors when I try to embed the other frameworks (like CoreMIDI):
“/Frameworks/CoreAudioKit.framework/Versions/A: bundle format unrecognized, invalid, or unsuitable”
Each framework I try to include in the iOS build target is throwing these errors. It seems like maybe this is because the project was exported from Projucer for OSX, and it doesn’t like bundling them for iOS, but that’s just a guess…
Would love to get this plugin working in our game on iOS if anyone has any ideas, thanks.
Hi there! Apologies for bringing this thread back to life, but I’ve recently written an article that offers a straightforward solution for integrating JUCE plugins into iOS Unity projects. It’s arguably easier than previous methods and works well with recent development environments. You might find it helpful for resolving your issues with plugin integration. Check it out here. Hope it helps.