Bug with loading .bundle plugins on macOS (and the fix for it)

I spent a couple of hours today struggling to get the Steam Audio integration to work with FMOD for Unity. After a fair amount of work, I landed on this error:

Basically, I had the plugin file in the correct directory, but for some reason FMOD wasn’t recognizing it and only looking for a .dylib instead of a .bundle.

I did some more digging into the FMOD plugin source code, and I think I found the culprit(s). On about line 78 of PlatformPlayInEditor.cs is the following function:

#if UNITY_EDITOR
        internal override string GetPluginPath(string pluginName)
        {
            string platformsFolder = $"{Application.dataPath}/{RuntimeUtils.PluginBasePath}/platforms";

#if UNITY_EDITOR_WIN && UNITY_EDITOR_64
            return string.Format("{0}/win/lib/x86_64/{1}.dll", platformsFolder, pluginName);
#elif UNITY_EDITOR_WIN
            return string.Format("{0}/win/lib/x86/{1}.dll", platformsFolder, pluginName);
#elif UNITY_EDITOR_OSX
            string pluginPath = string.Format("{0}/mac/lib/{1}.bundle", platformsFolder, pluginName);
            if (System.IO.File.Exists(pluginPath)) // <--- it's a folder/directory, not a file, so this fails!!
            {
                return pluginPath;
            }
            else
            {
                return string.Format("{0}/mac/lib/{1}.dylib", platformsFolder, pluginName);
            }
#elif UNITY_EDITOR_LINUX && UNITY_EDITOR_64
            return string.Format("{0}/linux/lib/x86_64/lib{1}.so", platformsFolder, pluginName);
#elif UNITY_EDITOR_LINUX
            return string.Format("{0}/linux/lib/x86/lib{1}.so", platformsFolder, pluginName);
#endif
        }
#endif

line 89 is incorrect. As my added comment notes, for macOS the .bundle items are folders, not files, so System.IO.File.Exists(pluginPath) returns false, because no file at that path exists. Changing line 89 to if (System.IO.Directory.Exists(pluginPath)) makes the error go away and my audio play as expected.

The function GetPluginPath() on line 74 of PlatformMac.cs needs to be changed in the same way, I would assume - change line 77 to if (System.IO.Directory.Exists(pluginPath)).

Thank you for reporting this, the fix for this will be out in the next release.

1 Like

Thanks so much! :smiley: