FMOD: Cleaning up duplicate platform warning

Hey there, I never got a reply from support.

Sorry to be a nuisance, I just wanted to be sure someone saw my email. I sent it quite some time ago.

I encountered the following errors with FMOD 2.01.07 and Unity 2019.4.17f1 on macOS 11.2.1:

ArgumentException: An item with the same key has already been added. Key: playInEditor
ArgumentException: An item with the same key has already been added. Key: default
ArgumentException: An item with the same key has already been added. Key: Default

etc.

This is how I fixed it. I had to edit the file Assets/Plugins/FMOD/src/Runtime/Settings.cs and made the following change to line 832:

if (existingPlatform != null && existingPlatform != newPlatform)

1 Like

Sorry about that - things got held up in the legal department. We should have some progress soon.

Thanks for the additional information. This does sound like the same issue @VoodooDetective is having - once we have their project we should be able to debug it further.

1 Like

Hi, Apologies for the delay, to update on the NDA side of things: After review, we cannot accept every customer’s NDA that exposes us to unknown damages from perceived breaches, from many other countries with legal jurisdictions that are not our own. The risk to benefit ratio is too high.

The only recommendation is to send the data through to us regardless - based on our reputation as a company that has been in business for 20 years without any legal incident, or rename strings in your project if they are of sensitive nature.

We treat any customer data as confidential by default, and it is usually deleted after a case is closed.

Gotcha. Where I’m from, trust is earned and so far, I haven’t been given many reasons to trust you. The number of problems I’ve run into is scary to me and I have no way of knowing how far these troubles extend into your company. How can I trust that you are capable of safeguarding our data?

The help I’ve received here on the forum has been great, and I’d like to continue using FMOD, but where my company is concerned, I’m not taking chances. I’m sure you can understand as another person in charge of other people’s livelihoods.

THAT SAID, in my free time this past month, I’ve been able to strip all content I was worried about sharing from the reproduction so I can upload it now. It should be there.

bump

bump

Apologies for the long delay on this issue, and thanks very much for taking the time to send us the reproduction project. After digging into it, I can see that Settings.OnEnable() is being called on an object that is already initialized, which is unexpected. This seems to be caused by the combination of two things:

  • The Actor Name Enforcer script on the Test prefab has an OnValidate() method that modifies the prefab.
  • The GUID used by FMODStudioSettings.asset is broken somehow (changing the GUID in FMODStudioSettings.asset.meta makes the problem go away).

Since I don’t have access to the Unity source code, I can only speculate on the reason for Unity calling Settings.OnEnable() unexpectedly in this situation. I suspect that the OnValidate() method modifying the prefab marks it as dirty, triggering a reimport cycle that the Settings object gets caught up in because its GUID collides with that of some internal Unity object.

Regardless of the exact cause, we have implemented a fix that ignores any Settings.OnEnable() calls on objects that are already initialized. This fix will be in the next release, or I can send you an updated Settings.cs file if you prefer.

Oh that’s fantastic! I’d surely appreciate and updated Settings.cs! I’ll also be on the lookout for the latest version. Would that be 09?

Thanks very much for taking a look at this, I really appreciate it!

The fix will be in the 2.01.10 release. I’ve attached Settings.txt (51.1 KB) - just rename it to Settings.cs, put it in your project, and hopefully it will resolve the problem for you!

Thanks again, and please let us know if you have any further issues.

Awesome, thanks! I’ll be testing it out. Thanks for digging into this.

Hello!
I have encountered similar problem with 2.02.04 integration. Method FMODUnity.Settings.OnEnable() was called multiple times after script recompilation, and strangely, hasLoaded flag was always false. So I got ArgumentException: An item with the same key has already been added. because initialization ran a few times. I found this was caused by another plugin. That plugin was creating assets and calling AssetDatabase.SaveAssets() from static constructor (probably not a very good idea). So, fixing that plugin also fixed error in FMOD.

Also, I get the same exception whenever FMODSettings.asset is changed externally by version control (for example when changes are reverted in SVN). Probably this is because the Settings object gets re-created, and OnEnable runs again, but dictionary PlatformForBuildTarget inside EditorSettings object is not re-created, and is populated already.

Thanks!

Seconding that I’m having the same issue as DmitryK, also in FMOD 2.02.04, on Unity 2021.2.11f1

Update: Removing my FMOD integration and reimporting from the Unity Package Manager fixed my issue. I’m not sure if it’s something to do with the fact I updated from an earlier version of FMOD partway through this project, or something else weird, but this seems to have fixed things for now.

I’m now having this issue again. Same FMOD/Unity versions as before, and after someone modified the FMODStudioSettings.asset in source control, it all went to pot again.

UPDATE: Okay, I have found a new, dumb fix for this, but at least it’s a quick dumb fix. I have no idea why it works, but this worked for me:

-Modify settings.cs in some way
-Tab back to Unity so it will recompile
-Revert those changes to settings.cs
-Get Unity to recompile again
-Mysteriously fixed???

1 Like

I have these issues too from the 2.01 versions.

Saved my bacon, thank you!!

1 Like

Apologies for the delay on this issue. I believe we have a fix, but it will be a while before it is released. In the meantime, you can modify the code yourself if you like:

  1. In Assets/Plugins/FMOD/src/Editor/EditorSettings.cs, add a public void Clear() function so it looks like this:

            [MenuItem("FMOD/Edit Settings", priority = 0)]
            public static void EditSettings()
            {
                Selection.activeObject = Settings.Instance;
                EditorApplication.ExecuteMenuItem("Window/General/Inspector");
            }
    
            public void Clear()                             // <= Add these lines
            {                                               // <=
                PlatformForBuildTarget.Clear();             // <=
                binaryCompatibilitiesBeforeBuild = null;    // <=
            }                                               // <=
    
            public void CreateSettingsAsset(string assetName)
            {
    
  2. In Assets/Plugins/FMOD/src/Settings.cs, find public interface IEditorSettings and add void Clear(); so it looks like this:

        public interface IEditorSettings
        {
    #if UNITY_EDITOR
            Settings RuntimeSettings { get; set; }
            bool ForceLoggingBinaries { get; }
            Platform CurrentEditorPlatform { get; }
            void Clear();                                   // <= Add this line
            void ResetPlatformSettings();
            void ReimportLegacyPlatforms();
            ...
    
  3. Still in Assets/Plugins/FMOD/src/Settings.cs, find public void OnEnable() and add editorSettings.Clear(); so it looks like this:

            public void OnEnable()
            {
                if (hasLoaded)
                {
                    // Already loaded
                    return;
                }
    
                hasLoaded = true;
    
    #if UNITY_EDITOR
                if (editorSettings != null)
                {
                    editorSettings.Clear();                 // <= Add this line
    
                    editorSettings.RuntimeSettings = this;
                }
    #endif
                ...
    
2 Likes