Trying to check if all sounds in mixer have been assigned to a group (outside of playmode)

Hello!

I’m trying to check if all sounds in my mixer have been assigned to a group there using a Unity Script.
Is there a way to check whether sounds have a group there, or how many sounds are contained in a group compared to the total amount in master bank using bank.getEventCount(out int eventCount); ?
Or maybe via the eventDescription itself?

Some more context:
I set my volume in Unity via a few VCA’s.
I want to prevent uncategorized sounds that are only mutable with the Master slider, so I want to display an error everytime a sound hasn’t been assigned to a group yet.

Another problem:
I’ve tried to check this during playmode using the RuntimeManager.StudioSystem (which works), but I would love to be able to check this outside of playmode as well. This is what I’ve tried there:

using System;
using UnityEditor;
using UnityEngine;

[InitializeOnLoad]
public static class FMOD_GuidsEvaluator
{
	private static FMOD.Studio.System studioSystem;
	private static FMOD.RESULT result;

	static FMOD_GuidsEvaluator()
	{
#if UNITY_EDITOR
		EditorApplication.delayCall -= Evaluate;
		EditorApplication.delayCall += Evaluate;
#endif
	}

	private static void Evaluate()
	{
		result = FMOD.Studio.System.create(out studioSystem);
		if (!CheckResult())
			return;

		result = studioSystem.initialize(512, FMOD.Studio.INITFLAGS.NORMAL, FMOD.INITFLAGS.NORMAL, IntPtr.Zero);
		if (!CheckResult())
			return;

		result = studioSystem.getBankByID(FSPRO.Bank.Master, out FMOD.Studio.Bank bank);
		if (!CheckResult())
			return;

		result = bank.getEventCount(out int eventCount);
		if (!CheckResult())
			return;

		Debug.Log(bank.handle + "  count " + eventCount);
	}

	private static bool CheckResult()
	{
		if (result != FMOD.RESULT.OK)
		{
			Debug.Log(result);
			return false;
		}
		return true;
	}
}

This gives me issues because it can’t find the bank by ID. This ID is from the exported GUIDs header file. I get the error: ERR_EVENT_NOTFOUND. If I look up the banks with:

result = studioSystem.getBankList(out FMOD.Studio.Bank[] banks);
if (!CheckResult())
	return;

The array is empty. This does work with the RuntimeManager.StudioSystem, though.

Thanks, Michael

Hi,

Unfortunately, while you can check which events a bank contains, there’s no simple way to check that an event has been assigned to a specific group bus via code. Is there a specific reason why confirming that an event is routed to a given group in FMOD Studio isn’t sufficient or possible in your case?

Additionally, the code snippet has two issues:

  • Replace getBankByID() with loadBankFile() - getBankByID() retrieves a loaded bank with the matching ID, and since you haven’t loaded any banks, it won’t return the one in question. loadBankFile() itself will return a Bank for you to call getEventCount() on anyway

  • Currently your FMOD Studio system is never released (it isn’t in the snippet, at least) - you’ll want to make sure to call Studio::System::release after you’re done with it

Hi Louis!

Thanks for the reply. I would love to be able to throw an error in Unity when the sound hasn’t been assigned to any group but the Master Bus yet! It’s easy to forget sometimes when working in a team. I would love to “confirm that an event is routed to a given group in FMOD Studio” programmatically for that reason.

Greetings,
Michael

I can definitely see the use-case for being able to retrieve event descriptions from a bus, which would address your needs - I’ve added this feature to our internal feature/improvement tracker.

While there is no simple way of programmatically checking whether an event is routed to a specific bus at run-time, it would be possible to do so when building banks using a Studio script that does something like write the names of events that are routed directly to the master bus to a file, so that you can confirm whether that’s the case outside of Studio. If that sounds like it’d be useful, I’d be happy to create a simple script for you that does so.

Hi Louis,

If you have time to create a script for me to check that, that would be amazing! Could you make it throw an error on build? I was wondering if something like this would be possible as well, but I could only find stuff about unity plugins on the documentation.

Greetings,
Michael

Here’s a simple script that will pop up a window displaying the names of all events directly routed to the master bus. If no events are routed to the master bus, it will instead build the project. You can place it in a .js file in the ./scripts folder of either your Studio install directory, or your project directory. If you run into any issues with it, feel free to let me know.

Click here to display script
studio.menu.addMenuItem({
    name: "Check Event Routing And Build",
    execute: function() {
        checkEventRoutingAndBuild();
    }
});

function checkEventRoutingAndBuild(){

    // iterate over all inputs routed into master bus
    var eventNames = "";
    for (var i = 0; i < studio.project.workspace.mixer.masterBus.input.length; i++){
        // if input is an event, add to list of event names routed to master bus
        if (studio.project.workspace.mixer.masterBus.input[i].isOfExactType("MixerInput")){
            eventNames += studio.project.workspace.mixer.masterBus.input[i].event.name + "\n";
        }
    }

    // if some events are routed directly to master, display modal dialog and show all event names, else build banks
    if (eventNames !== ""){
        console.log(eventNames);
        studio.ui.showModalDialog({
            windowTitle: "Warning - Events routed to Master Bus",
            widgetType: studio.ui.widgetType.Layout,
            layout: studio.ui.layoutType.VBoxLayout,
            items: [
                {
                    widgetType: studio.ui.widgetType.Label, text: "The following events are routed to the Master Bus:\n\n"
                    + eventNames
                    + "\n"
                    + "Banks have not been built."
                }
            ]
        });
    } else {
        console.log("No events routed directly to Master Bus - banks have been built")
        studio.project.build();
    }

}

This script uses the Studio Scripting API. If you’re interested in learning more, the FMOD Studio documentation contains the (somewhat barebones) Studio Scripting API reference.

1 Like

Hi Louis,

Thank you so much! It works nicely :slight_smile:

I would assume it’s not possible, but I will look into whether I can hide the default Build option or reroute the F7 shortcut. When you get back to this post, could you answer that for me? Thanks for your help!

Greetings,
Michael

If you unbind the F7 hotkey from any actions it’s assigned to in Preferences → Shortcuts (“Build” by default), and add keySequence: "F7", to the script like so:

studio.menu.addMenuItem({
    name: "CheckEventRoutingAndBuild",
    keySequence: "F7", // <- keySequence line added here
    execute: function() {
        checkEventRoutingAndBuild();
    }
});

then F7 will trigger the script instead of the default build command.

Seems there’s no warning when the keybind is still bound to both, it just does nothing? Is it possible to display a warning for whenever a new user opens the project?

If the keybind is still bound to both, FMOD Studio will output a warning QAction::event: Ambiguous shortcut overload warning to the Console, which you can see by going to Window → Console → Logging. Besides that, unfortunately there’s no way to display an immediately visible warning about this to users on opening the project.

Okay, thank you for your help! I will bind it to a different key.