Unity FMOD plugin shows error when building the game

Hi,

When I’m trying to build our game I’m getting this errror:

NullReferenceException: Object reference not set to an instance of an object
FMODUnity.EditorSettings.PreprocessStaticPlugins (FMODUnity.Platform platform, UnityEditor.BuildTarget target) (at Assets/Plugins/FMOD/src/Editor/EditorSettings.cs:513)

and

NullReferenceException: Object reference not set to an instance of an object
FMODUnity.EditorSettings.PostprocessBuild (UnityEditor.BuildTarget target) (at Assets/Plugins/FMOD/src/Editor/EditorSettings.cs:494)

From what I’ve found the “Platform platform” variable is null. When I do any change in any class of the project and the project will recompile, the errors are gone and the project is building correctly.
However we use Unity Cloud Build where the same error occurs and a workaround with recompiling is not possible.

Are there any solutions to the problem?
If that is any helpful we don’t build the project with “Build” button in “BuildSettings” window. We do have our custom build methods and we call: BuildPipeline.BuildPlayer() method by ourselves.

I am using Unity 2021.2.17f1 and FMOD 2.02.04

Are you switching build target in your build script, i.e calling EditorUserBuildSettings.SwitchActiveBuildTarget?
If you are then you can instead use EditorUserBuildSettings.SwitchActiveBuildTargetAsync which will recompile scripts and fire a callback when script compilation is finished, and in that callback you can call BuildPipeline.BuildPlayer.
Otherwise, just to help me debug this issue, can you please tell me whether there are any platforms listed in the “Platform Specific” section of your Unity FMOD Settings?

I 'm not using EditorUserBuildSettings.SwitchActiveBuildTarget or EditorUserBuildSettings.SwitchActiveBuildTargetAsync right know, because I’m building for Windows, and the editor as well as Unity Cloud build is setup for Windows builds.

I tried to add EditorUserBuildSettings.SwitchActiveBuildTargetAsync call before the build, but with no success. In Unity Cloud Build I’m still getting same error:

My current FMOD Settings are listed below


When I’m selecting “Editor” right after I open the Unity Editor I’m getting such errors as well (I don’t know if it is somehow connected to the problem):

I think that would be connected to the problem. Would it be possible for you to upload a stripped down reproduction to your FMOD Profile? Just a project with all the assets removed except the Plugins/FMOD directory and some built banks should be sufficient to reproduce this.

Hey @jeff_fmod

Sorry for long reply, but I had a lot going on around the project.

I managed to strip out the whole project and leave only the necessary elements to test it out. After removing lots of stuff the problem with error in the FmodStudioSettings is gone, but the original errors with PreprocessStaticPlugins and PostprocessBuild still occur.

I cannot share the repro project publicly, but I will contact you by PM with all information. Is that okay?

That sounds like a good reproduction, thank you for taking the time to get that setup. Uploading it to your FMOD Profiler is private and secure, but feel free to pm me a link if you prefer.