fmod-gdextension

repository·master·Indexed 21 days ago

https://github.com/utopia-rise/fmod-gdextension

A Godot 4 GDExtension that integrates the FMOD Studio API into the Godot Engine. It provides dedicated nodes for event emission and listening (FmodEventEmitter2D/3D, FmodEventListener2D/3D), seamless bank loading, and live updating. The extension exposes the majority of FMOD Studio API functions to GDScript via the FmodServer singleton, allowing developers to manage banks, event instances, and global parameters.

Tokens
8.1K
Snippets
20
Records
42
Agent score
75%

What's inside fmod-gdextension

  1. Project structure for FMOD libraries

    master

    To follow the standard project structure, place your FMOD libraries in a libs folder that is a sibling to the fmod-gdextension repository. The hierarchy should look like this:

    └── Project root
        ├── libs
        |   └── fmod
        |       └── {platform}
        |           └── [platform specific fmod api]
        └── fmod-gdextension
            ├── SConstruct
            ├── godot-cpp (submodule)
            └── src
  2. Understand how the FMOD GDExtension works

    master

    This GDExtension exposes the majority of the FMOD Studio API functions directly to Godot's GDScript. It also includes high-level helpers for common tasks, such as:

    • Attaching Studio events to Godot nodes.
    • Playing 3D and positional audio.
    • Auto-loading all events from FMOD Studio bank files.

    Language Support Note:

    • GDScript: Fully supported via GDExtension auto-binding.
    • C#: Not directly supported. While a C# FMOD API exists, this extension is developed as a C++ GDExtension. C# users cannot currently use these bindings unless using a language binding feature that supports GDExtension auto-binding (which C# currently lacks).
  3. Choose an integration approach for FMOD

    master

    The FMOD GDExtension plugin provides two distinct ways to integrate FMOD into your Godot project depending on your needs:

    1. Using FMOD Nodes: Use predefined, high-level nodes for common audio tasks (like loading banks, playing events, or setting up listeners). This is the easiest approach for standard workflows.
    2. Using the FmodServer API: Use the FmodServer singleton for direct access to FMOD's core and system APIs. This is intended for advanced or highly customized workflows that require low-level control.

    Note that all FMOD nodes are built on top of the FmodServer singleton.

  4. Use dedicated FMOD Godot nodes

    master

    The extension provides specialized nodes to simplify audio implementation in Godot scenes or via GDScript. These nodes handle the attachment of FMOD Studio events to Godot objects and manage positional audio.

    Available nodes include:

    • FmodEventEmitter2D
    • FmodEventEmitter3D
    • FmodEventListener2D
    • FmodEventListener3D
  5. Implement Programmer Callbacks

    master

    Programmer callbacks allow FMOD to trigger logic in your game to provide audio data (like dialogue) from an external bank/audio table.

    Requirements

    1. The bank containing the audio table must be loaded.
    2. You must specify the key from the audio table using set_programmer_callback.

    Using Emitters

    event_emitter.set_programmer_callback("welcome") # "welcome" is the key in the loaded bank

    Using FmodServer

    FmodServer.load_bank("res://assets/Banks/Dialogue_EN.bank", FmodServer.FMOD_STUDIO_LOAD_BANK_NORMAL)
    var event_instance = FmodServer.create_event_instance("event:/Character/Dialogue")
    event_instance.set_programmer_callback("welcome")
    event_instance.start()
    # Programmer callback example with FmodServer
    FmodServer.load_bank("res://assets/Banks/Dialogue_EN.bank", FmodServer.FMOD_STUDIO_LOAD_BANK_NORMAL)
    var event_instance = FmodServer.create_event_instance("event:/Character/Dialogue")
    event_instance.set_programmer_callback("welcome")
    event_instance.start()
  6. Configure General FMOD settings

    master

    After adding the FMOD addon to your Godot project, you must configure the FMOD parameters within the project settings. The General category controls core engine behavior:

    • Auto Initialize: If true, FMOD starts automatically when the engine starts.
    • Channel Count: Sets the maximum number of Channel objects (virtual voices) available. Virtual voices allow for high-count playback with minimal overhead by mixing a subset of 'real' voices based on priority and audibility.
    • Live update: Enables FMOD's live update feature.
    • Memory Tracking: Enables detailed memory usage statistics (implies FMOD_INIT_MEMORY_TRACKING). This increases memory footprint and impacts performance. Use Studio::Bus::getMemoryUsage and Studio::EventInstance::getMemoryUsage to access these stats.
    • Default Listener count: Sets the maximum number of listeners (range: 1 to 8).
    • Should Load by Name: If true, FMOD nodes will load events and parameters using their string names instead of their IDs.
  7. Activate the FMOD GDExtension plugin in Godot

    master

    Once the files are in your addons folder, you must enable the plugin within the Godot editor:

    1. Open your Godot project.
    2. Navigate to Project > Project Settings.
    3. Select the Plugins tab.
    4. Locate FMOD GDExtension and check the box to enable it.

    After activation, you can create FMOD nodes, use the bank explorer, and access the FmodServer via scripts.

  8. Configure Android export for FMOD GDExtension

    master

    To use FMOD on Android, you must follow these steps:

    1. Install Android Build Template: In the Godot editor, go to the Project menu and select the option to download/install the Android build template.
    2. Enable Gradle Build: In your Android export settings, ensure the Use Gradle Build option is activated.

    Important Limitations:

    • Currently, only the armv8 architecture is supported for Android exports.
    • To support x86 architecture, you must build the plugin manually.
  9. Use FmodEventEmitter nodes to play events

    master

    The FmodEventEmitter2D and FmodEventEmitter3D nodes are the primary way to play FMOD events within the Godot scene tree. You can assign an event using its name or GUID.

    Key Properties

    • attached: If true, the event's position updates with the node's position.
    • autoplay: If true, the event plays automatically when the node is ready.
    • auto_release: If true, the emitter node is automatically freed when the event finishes.
    • allow_fadeout: If true, the event fades out when stop() is called.
    • preload_event: If true, the event is preloaded when the node is ready.

    Controlling Playback

    • play(restart_if_playing: bool = true): Starts the event. If restart_if_playing is true, it restarts the event if it is already playing.
    • play_one_shot(): Starts a one-shot instance of the event that is not managed by the emitter (ideal for short SFX).
    • stop(): Stops the event.
    • set_event_name(name: String) / set_event_guid(guid: String): Changes the event. These methods stop and unload the current event and clear parameter values. If preload_event is true, the new event is preloaded; if autoplay is true, it is also played.
    # Example of setting up an emitter in code
    var event_emitter = FmodEventEmitter2D.new()
    event_emitter.event_guid = "{9aa2ecc5-ea4b-4ebe-85c3-054b11b21dcd}"
    event_emitter.autoplay = true
    add_child(event_emitter)