+1
Fixed

Audio Mixer reference gets nulled on IL2CPP builds

Eric Welwood 2 years ago updated by Lazlo Bonin (Lead Developer) 1 year ago 17 1 duplicate

Whenever I try to interact with the Audio Mixer with bolt it never works in the build. Not only that but anything after the Audio Mixer flow also doesn't execute. The units I have attempted to use are switching snapshots and set float, all of which worked fine in the editor.

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):

Duplicates 1

Pending Review

Can you enable debug build and see if you get any errors in the logs?

Hi Eric,

Any change you're using the Audio Mixer on a WebGL build? Some features of audio mixer are not available in WebGL, regardless of Bolt.

I'm currently wanting to know if I can get output functions from Audio in Bolt, I really want to sample an output of an audio listener to control functions in shaders. Cheers...

Hey, I'm having the same issue here : 



And here is the graph that is causing the error (and as it was previously said, it's working in the editor, no warning messages in the console window) :


Same with : 




(I'm actually muting the in-game mixer for my pause menu) 


Using Unity 2017.3.0p1
Bolt 1.3.0

Hmm, from those errors it seems like the audio mixer group reference gets nulled on build.

There is this issue that seems to be related: https://forum.unity.com/threads/unity-5-audiomixer-nullreference-on-ios-using-il2cpp.313333/

I wonder if putting the AudioMixer object in a resources folder would prevent Unity from stripping it in builds. Can you give it a try?

+1

After further investigation, this seems like an often encountered Unity bug.

Apparently, object references to AudioMixer assets get nulled in some builds (I believe it only happens in IL2CPP builds).

This was mentioned by users on the Unity community here:

There is also this bug report which seems tangentially related, although not quite the same (it mentions the return value of the method is null, not the instance itself):

My educated guess is that asset stripping wrongfully flags the audio mixer asset as unused in the project and strips it from the build. This in turn makes any method that used it as a target throw a NullReferenceException at runtime.

From that guess, a potential workaround would be to put your AudioMixer asset (*.mixer) under a Resources/ folder. This usually forcefully disables asset stripping and could fix the issue.

If that doesn't work, a proper bug report should be submitted to Unity. I'm very tight on time at the moment so I don't have time to do it myself, but the report should:

  • Create a simple MonoBehaviour script with an AudioMixer public field assigned to something
  • Use the AudioMixer field in one of its methods (e.g. mixer.SetFloat in Start)
  • Show that it works in the editor
  • Build for a failing platform like iOS/IL2CPP and show that you get a NullReferenceException
+1

I tried a build putting the AudioMixer under a Resources folder but the same problem exists, my current builds work fine using a script to control the audio mixer and bolt for rest so this doesn't stop me doing anything, will look into what I need to do/supply to submit a bug to unity

This happened to me on my Bolt Jam and it was targeted to standalone with Mono scripting backend.
I did a build that had a script and a flow graph to trigger transitions, the script worked, bolt failed.

So audio mixer aren't missing references in the project, only Bolt misses it.

Same problem here, AudioMixer donest work on mobile... iOS and Android.

InvalidOperationException: Missing target object for 'UnityEngine.Audio.AudioMixerSnapshot.TransitionTo'.
at Ludiq.Member.EnsureReady () [0x00000] in <filename unknown>:0
at Ludiq.Member.EnsureInvocable () [0x00000] in <filename unknown>:0
at Ludiq.Member.Invoke (System.Object arg0) [0x00000] in <filename unknown>:0
at Bolt.InvokeMember.Invoke (Bolt.Flow flow) [0x00000] in <filename unknown>:0
at Bolt.InvokeMember.Enter (Bolt.Flow flow) [0x00000] in <filename unknown>:0
at Bolt.Flow.InvokeDelegate (Bolt.ControlInput input) [0x00000] in <filename unknown>:0
at Bolt.Flow.Invoke (Bolt.ControlOutput output) [0x00000] in <filename unknown>:0
at Bolt.Flow.Invoke (Bolt.ControlOutput output) [0x00000] in <filename unknown>:0
at Bolt.Flow.Invoke (Bolt.ControlOutput output) [0x00000] in <filename unknown>:0
at Bolt.Flow.Run (Bolt.ControlOutput port, Boolean coroutine) [0x00000] in <filename unknown>:0
at Bolt.EventBus.Trigger[TArgs] (EventHook hook, .TArgs args) [0x00000] in <filename unknown>:0
at Bolt.EventMachine2[TGraph,TMacro].TriggerRegisteredEvent[TArgs] (EventHook hook, .TArgs args) [0x00000] in <filename unknown>:0 at Bolt.EventMachine2[TGraph,TMacro].TriggerEvent (System.String name) [0x00000] in <filename unknown>:0

(Filename: currently not available on il2cpp Line: -1)


output from xcode



Pending Review

This is puzzling, especially if scripts manage to keep the reference and not Bolt. Bolt doesn't have any kind of special handling for Audio Mixers at all, so I don't understand why it would behave differently than a script.

I'll reopen this as Under Review to remind me to post a bug report to Unity. But if either of you has a simple project they could use as a report already, it would be greatly appreciated if you could submit the report yourself, because setting up an iOS build project is going to take a few hours of my time, so I can't prioritize it right now. Thanks!

Working on Fix

So I finally had a chance to give this bug a look, and you guys forgot to paste half the errors! ;)

The main culprit is this error: 

[Deserialization] Unable to find type: 'UnityEditor.Audio.AudioMixerController'.

The problem is that Bolt serializes a reference to the actual object we provide it from the editor, that is, the Controller. But the Controller is an Editor only class that extends the runtime class that isn't a controller (e.g. AudioMixerController extends AudioMixer). Once in a build, Bolt can't find the controller because the editor assemblies haven't been packaged, so it fails to deserialize the reference's type and stops there.

I'm investigating how to fix this... it's not quite obvious with how our serialization engine is laid out. It's kind of a weird architecture decision from Unity to make editor references extend runtime classes.

+1
Fixed in Next Version

Alright, I put a tentative fix in place for 1.4.0f12. It's messing with very core serialization type hints, so I'm thinking of having a beta for the next version just to make sure everything runs fine without any data loss.

Just to give you a funny look at how ridiculously edge-cased some of these bug fixes can be, here's my comment for this one: