Answered
1
0

First of all, I love the marker and tempo system in Fmod Studio – it’s great! One thing I’d really like to be able to do is get access to a list of all the markers in a given EventInstance. I’m working on a music game and I want to be able to mark specific, musically relevant moments in Fmod Studio that my game code can watch for and then react to with cool particle FX, animations, etc.

I was hoping that getSyncPoints() on the Sound class might contain marker data but my testing indicates that this isn’t the case. Is there another place this information is stored that I could get at, or is it simply not accessible? All I really need is a list of markers with their names and timeline positions so that I can use getTimelinePosition() to trigger events in my game when specific markers are reached.

If anyone knows if this is possible and/or how to achieve it I would be very grateful. Thank you for your time!

  • You must to post comments
Best Answer
0
0

Currently this is not exposed to the API, but it is a good suggestion. We’ll look at exposing it in a future revision. There would be two ways of getting it, one would be from the event description, and another would be to receive a callback when passing a marker on an instance.

  • Richard Simms

    Hi Anteevy,

    An alternative you can use is to enter all known markers into the event’s User Properties section (under the Overview on the far right hand side) and then to use Studio::EventDescription::getUserProperty to pull this information out.

    https://www.fmod.org/docs/content/generated/FMOD_Studio_EventDescription_GetUserProperty.html

    This way you will have the names of the markers without needing to play the event itself and without any extra metadata files.

    Thanks,
    Richard

  • anteevy

    Cool, that also helps a lot, didn’t know that. Thanks!

  • Josh Sutphin

    Did this ever get added to the API? I actually have a use case where I really do need to know where the markers are in the event ahead of time, before playback begins. Waiting for the callbacks to be fired is going to be far too late.

  • Richard Simms

    Hi Josh,

    This has not been implemented yet, but it is in our tracker.

    If you really need the exact times of markers you could use the FMOD Studio scripting API to grab the times of all markers in an event.

    https://www.fmod.com/resources/documentation-studio?page=scripting-terminal-reference.html

    Take a look into an event’s array of markerTracks for the position of any ManagedObject::NamedMarker

    Thanks,
    Richard

  • Josh Sutphin

    Yup, just came back to say I figured this out using the scripting API and it’s not very difficult (as long as you’re basically familiar with Javascript). For future searchers, here’s a quick crash course in how to do this:

    First, make a folder called “Scripts” in your FMOD Studio project, and make an ExportMarkers.js inside that folder. This will be our simple Javascript plugin for automatically exporting the marker data from FMOD when we build our banks.

    In that script, create a Javascript function with the signature “onBuild(success)” and bind it to the build event like so:

    studio.project.buildEnded.connect(onBuild);

    In your onBuild, “success” will be true for successful builds and false for failed builds. Handle failure however you like.

    For successful builds, you can get an array of all events in the project like this:

    studio.project.model.Event.findInstances()

    Each event has an array called “markerTracks”, each MarkerTrack has an array called “markers”, and each marker has some different data depending on what kind of marker it is. The easiest way to get a feel for the different data layouts is to explore the data model in the FMOD Studio Console window (Ctrl+0). Here are some useful commands for that:

    // Get all events
    var events = studio.project.model.Event.findInstances()

    // See a list of events
    events

    // See a list of marker tracks within an event
    events[x].markerTracks

    // See a list of markers with a track
    events[x].markerTracks[y].markers

    // Show the json data structure of a given marker
    events[x].markerTracks[y].markers[z].dump()

    In your Javascript, you basically just iterate over all events (and all their marker tracks (and all their markers)), extract whatever data you care about into some data structure that’s useful to you, then write the resulting data structure to some .json file you can then read in on the game side. The basic file I/O works like so:

    var file = studio.system.getFile(outputPath);
    file.open(studio.system.openMode.WriteOnly);
    file.writeText(JSON.stringify(yourDataStructure));
    file.close();

    I’ll leave robust error checking, etc. as an exercise for the reader. For the outputPath, note that you can get the current path of the FMOD Studio project file with:

    studio.project.filePath

    In my case, our FMOD studio project lives inside our Unity project folder, so I just took studio.project.filePath and walked up the directory tree until I found the Unity project root, than tacked on “/Assets/Resources/markers.json”. You can do whatever makes the most sense for your game.

    On the game side, you’ll need some way to deserialize the .json file into some usable data structure. Unity has a nice JSONUtility class that makes this easy. Once you’ve deserialized the data, it should be trivial to figure out what markers you have available, what they’re called, where they fall in time, and any other data you chose to capture in your export script.

    Feel free to correct inaccuracies or point out better ways of doing this!

Showing 1 result
Your Answer

Please first to submit.