Unity Plugin, Mobile Build Support

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.

Thanks!

+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.

1 Like

How does Helm do it? That’s made with JUCE.

Guessing “manually”.

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. :wink:

1 Like

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.

Yeah, totally agree with getting this! It would be absolutely awesome.

Did anyone on this thread manage to get it working?

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 :slight_smile:

  1. Create your plugin with a name like “audioplugin_MyPlugin”.
  2. Create a MacOSx exporter of your plugin.
  3. 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.
  4. Select the library and then go to Build Phases and add the “include_juce_audio_plugin_client_Unity.cpp” to your compile sources.
  5. Then build the static library. Make sure you select the correct build configuration so you build the iOS one and not the MacOSx one.
  6. Drag and drop your static library plugin into your Unity projects “Plugins/iOS” folder
  7. Click on the plugin and within the inspector select the following frameworks which JUCE depends on: Accelerate, CoreImage and MobileCoreServices
  8. Create a file “MyPluginAppController.mm” within the “Plugins/iOS” folder
  9. 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:
#import "UnityAppController.h"

@interface MyPluginAppController : UnityAppController {}
@end

extern "C" {

// We have to manually register the Unity Audio Effect plugin.
struct UnityAudioEffectDefinition;
typedef int (*UnityPluginGetAudioEffectDefinitionsFunc)(
    struct UnityAudioEffectDefinition*** descptr);
extern void UnityRegisterAudioPlugin(
    UnityPluginGetAudioEffectDefinitionsFunc getAudioEffectDefinitions);
extern int UnityGetAudioEffectDefinitions(UnityAudioEffectDefinition*** definitionptr);

}  // extern "C"

@implementation MyPluginAppController

- (void)preStartUnity {
    [super preStartUnity];
    UnityRegisterAudioPlugin(&UnityGetAudioEffectDefinitions); // intialize native audio plugins
}

@end

IMPL_APP_CONTROLLER_SUBCLASS( MyPluginAppController )
  1. Then set your player build settings to be iOS and generate the Unity iOS XCode project by clicking “Build”
  2. Select your .app target and set your app signing credentials.
  3. 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.

Hope it helps some of you!