Variable unresponsive when building for android

I use a straightforward system to mute audio in my game which works flawlessly in the editor:


(Elsewhere I have a simple button setting AudioMuted to True or False when clicking it)

The only problem is that it doesn’t work when I build for Android.
I’ve tried making the On Update a coroutine and using On Late Update instead. When doing so everything still works fine in the editor, but not when I build for Android.

I also tried building using IL2CPP instead of Mono, which doesn’t make any difference.

Please help - Am I missing something obvious or have I encountered a nasty bug?

Thanks!

I’m not sure if it makes any difference, but I might add that the visual script pictured above is attached to a persistent game object which is loaded in a bootstrap scene before loading the first game scene…

It’s been a while and I find it odd that there isn’t even a response from a unity staff.
I’m a paying customer and this is a major issue going forward.
If anyone has any ideas or workarounds, please let me know.
Thank you.

You may see staff respond to threads every once in a while, but that’s not really what the forum is for. Generally, it’s just users helping other users voluntarily, and there is no requirement for staff to answer questions on here.

Most likely the reason no one has responded is

  1. I don’t know what the adoption rate is for Visual Scripting over all, but my impression is that not many people use it.

  2. There is not nearly enough information in your post to diagnose the issue.

I think the graph in your first post is almost too simple to fail, so I imagine the problem is actually somewhere else. You’ll want to test any of the various things that could cause it not to work. For example, is the GameObject this is attached to actually exist and is active? Is the button detecting input? Is this logic actually subscribed to the button’s OnClick event, and so on…

One reason that scripts might work in the editor but not the build is that GameObjects can initialize in a different order in a build than they do in play mode. For example, If GameObjectA is trying to access reference variables from GameObjectB in the Awake event, it might work in playmode if GameObjectB’s Awake event always runs first. In the build, GameObjectA’s Awake event might run first and so it would access these variables before GameObjectB can initialize them. Check and see if something like that is happening.

Thank you very much for your reply @kdgalla !
Exactly because my script is so simple, it is quite frustrating why it does not work once compiled to Android.

The gameObj I have with the visual script (screenshot from my main post) is loaded in my first bootstrap scene on a persistent gameObj and then it is carried to the next scene. It is only in my second scene the functionality to mute becomes available, so there can be no doubt about the load order unless persistent gameObj loads after the initial scene objects.

Regardless, do you agree that a script that simply checks every update whether a saved bool is true or false should work isolated from the load order of other objects? So as long as the the bool is correctly set, the script should work, right?

Thanks again

Have you checked to make sure that this is the case?

And building on that, remember to check if it is the SAME bool you think it is.

I haven’t used Visual Scripting hardly at all, but like all Unity instance stuff, it’s always possible to have more than one of these things at a time and this is a frequent source of confusion.

To figure it out, you pretty much have to debug it with an eye to understanding what is where and what it is all connected to.

Here’s my standard debugging blurb for code, but troubleshooting is troubleshooting:

Sounds like you wrote a bug… and that means… time to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.

Good point - but yes, I have added some debug UI which checks the bool every update and prints it state to the UI like this:
Screencast from 2025-03-19 10-47-15

This also works when compiled for Android, so I am certain the bool is correctly set.
The odd thing is that the visual code snippet used to update the debug UI is almost identical to the visual code that is not responsive (when building to Android):

Which makes me truly baffled as to what could be the issue.

@Kurt-Dekker Thank you for your input.
As I wrote in the original post, the functionality works flawlessly in the editor, so I am certain it is the correct bool (unless Unity would somehow mix up my variables when building for Android specifically).

UPDATE: PROBLEM RESOLVED.

It turns out not to be related to the reading of the boolean variable, but because AudioListener for some reason works differently when building to Android than when building to PC… :

Thank you @kdgalla and @Kurt-Dekker for your input, which eventually helped pinpoint the cause of the problem. Have a great day!

Cheers