How do I set the max instances of an event based on build platform?

Hi!
Is it possible to set the max instances of an event differently depending on which platform (Desktop, PS4, XBOX ONE, Switch) the event is currently playing on?

Right now we have an issue with the Switch not handling a certain amount of simultaneous events (too many instances of the same event) while the rest of the platforms are fine. So I would like to set the “Max Instances” option to a lower number on the Switch, but leave the other platforms intact.

Basically, what I want to do is to have some base settings, which I then can override on a per-platform basis for each event. Is that possible somehow?


Running on FMOD Studio 1.10.15
The game is being made in Unity 2018.4.11f1


Regards,

Pablo Sorribes Bernhard
contact@pablosorribes.com
pablosorribes.com

@Derek_Burnheim @cameron-fmod , do you guys know something about this topic? Is it possible to do it programmatically at least?

/Pablo

In the API it currently isn’t possible to change event instance limits at runtime, however you can create a custom build script in order to achieve this.

The script will perform the following actions:

  1. Build all other platforms with the project as-is
  2. Have an array of all necessary events to apply the limiting to (if you are limiting all events, use studio.project.model.Event.findInstances())
  3. Set all those events’ instance limits to whatever limit you need using event.automatableProperties.maxVoices = <number>
  4. Build the Switch banks
  5. Set the event instance limits back to what they were previously
  6. Save the project

Another option is to create your own instance limiting system in your game, checking the number of instances of an event each frame.

Hi @richard_simms, thanks for the suggestion.

Could you show me an example script for doing this? I’ve never done scripts for FMOD Studio, so I don’t really know where to start or how the API works for starting your own build process.

Didn’t know about automatableProperties, that sounds very nice.

@Paalo paste this in a new .js file in the Scripts folder of your FMOD Studio project (create it if not present):

studio.menu.addMenuItem({
name: "Unity\\CustomMaxVoices",
isEnabled: function() {
    var events = studio.window.browserSelection();
    return events
},

execute: function() {
    var events = studio.window.browserSelection();

    var oldVoiceNumber = [];
    var voiceNumber = studio.system.getNumber("Enter the max voices for the selected events", "0");
    var platform = studio.system.getText("Enter the Platform", "Switch");

    for (x = 0; x < events.length; x++) {

        oldVoiceNumber[x] = events[x].automatableProperties.maxVoices
        events[x].automatableProperties.maxVoices = voiceNumber;
    }

    studio.project.build({
        platforms: platform
    });

    for (x = 0; x < events.length; x++) {
        events[x].automatableProperties.maxVoices = oldVoiceNumber[x];
    }
}});

While having the Events selected, for which you want to change the voice value, go to Scripts->Unity->CustomMaxVoices, enter the max voices number and the Platform in the pop ups. It should automatically build all the Banks for the Platform you specified and revert the voice number back to the original value. Let me know if it works, wrote it quickly : )

Wow, cool! Gotta try it when I get home!
Thanks for the writeup @alexzzen! :slight_smile:

Also, quick question: This will presumably just change the selected event for that one time I build the banks, right?

Given that, how would I go about affecting all the events I want to have overriden for Switch and saving the settings for each incremental build?

I’m thinking a possible solution would be to have a .txt or .json-file which lists all the events I wanna have overriden and where I can edit the number for that event via comma-separation. I’m thinking that the file should look something like this:

//string eventPath, int overriddenEventInstanceValue;

event:/MyTestFolder/SubFolder/testEvent, 5;
event:/MyTestFolder/SubFolder/otherEvent, 3;
event:/MyTestFolder/SubFolder/moreAllowingEvent, 15;

That way I could just copy-paste the path of the offending events into that text file and have the Switch-specific settings be saved for all future builds using this script.

You got any idea on how to implement this?

@Paalo I think it’s possible! Note that I’m a self taught when it comes to programming, so make sure to test this :smiley:
I would first export a .json file from FMOD Studio with the selected FMOD Events in the hierarchy:

studio.menu.addMenuItem({
name: "Unity\\ExportEventsVoiceJson",
isEnabled: function() {
    var events = studio.window.browserSelection();
    return events
},

execute: function() {
    var events = studio.window.browserSelection();

    var eventsObj = [];
    var event = {};

    for (x = 0; x < events.length; x++) {

        var newEvent = events[x].getPath();
        var newVoices = events[x].automatableProperties.maxVoices

        eventsObj.push({
            'path': newEvent,
            'value': newVoices
        })
    }

    event.eventsObj = event;

    var str = JSON.stringify(eventsObj, null, 2);

    var fileName = studio.system.getText("File Name", "NewFile");
    var projectPath = studio.project.filePath;
    projectPath = projectPath.substr(0, projectPath.lastIndexOf("/"));
    var filePath = projectPath + "/" + fileName + ".json";
    var file = studio.system.getFile(filePath);

    file.open(studio.system.openMode.WriteOnly);
    file.writeText(str);
    file.close();
}});

This will create a new .json file in the root directory of your FMOD project. It will look like this for example:

[
  {
"path": "event:/2_Playing FMOD Events/2D Event",
"value": 1
  },
  {
"path": "event:/2_Playing FMOD Events/3D Event",
"value": 2
  },
  {
"path": "event:/2_Playing FMOD Events/Loop",
"value": 3
  }
]

Now manually change the values in the .json file to your desired max voices for each event.
This script will read the .json file, apply the voices values you specified in the .json file, build the banks for your desired platform and revert the values back to the original state. Just enter the platform and the file name of the .json file created earlier.

studio.menu.addMenuItem({
name: "Unity\\CustomMaxVoicesJSON",
isEnabled: function() {
    return 1;
},

execute: function() {

    var oldVoiceNumber = [];
    var platform = studio.system.getText("Enter the Platform", "Switch");

    var fileName = studio.system.getText("File Name", "NewFile");
    var projectPath = studio.project.filePath;
    projectPath = projectPath.substr(0, projectPath.lastIndexOf("/"));
    var filePath = projectPath + "/" + fileName + ".json";
    var file = studio.system.getFile(filePath);
    file.open(studio.system.openMode.ReadOnly);

    var fileSize = file.size();

    var events = JSON.parse(file.readText(fileSize));

    for (x = 0; x < events.length; x++) {

        var event = studio.project.lookup(events[x].path);
        var value = events[x].value;

        oldVoiceNumber[x] = event.automatableProperties.maxVoices;

        event.automatableProperties.maxVoices = value;
    }

    studio.project.build({
        platforms: platform
    });

    for (x = 0; x < events.length; x++) {
        var event = studio.project.lookup(events[x].path);

        event.automatableProperties.maxVoices = oldVoiceNumber[x];
    }
}});

I guess you can skip the first script if you manually create the .json file, but you know, it’s fun to also automate that the very first time.

Wow, thanks! I’ve got to try this out!
And if this works, I’m gonna add you in the credits dude! :smiley:

1 Like