How to use c# in Godot?

I cannot for the life of me get Fmod to interact properly with Godot via c# which my gamejam team is using.
I cannot find any resources online about how to properly trigger events in Godot via c#, I can only find gd script advice.
Does anyone know of any tutorials or pages that could help me?

As we don’t officially support 3rd party Godot integrations, if you’re running into issues on the integration side of things then unfortunately I can’t be of much help. If you’re having issues with the FMOD API/Engine itself, then I should be able to assist you. Can I get you to elaborate on the exact nature of the issues you’re running into?

That said, a broad outline of how to get your events to play can be found in the Playing Events section of the Studio API Guide, and you can also take a look at the Studio API examples provided with the FMOD Engine installer. These example are in C++, but should still serve as a general guide. Additionally, while they do involve calls into the integration-specific code, our Unity scripting examples may also be useful, specifically the “Basic” example.

Hi, thanks for your response - I’ve tried using these resources to get an fmod event to play every time the script enters the scene (which I am able to do in .gd script) however I can’t seem to get it to work in godot with c#. Would you be able to help?

The godot script is below and I’d like to be able to also do this with c#.

extends Node2D

var instance: EventInstance

func _ready():
pass # Replace with function body.
instance = FMODRuntime.create_instance_path(“event:/Crypt”)
instance.start()

func _process(delta):
pass

Unfortunately, this appears to be an issue with the integration you’re using. Based on Godot’s C# style guide and basic examples in their documentation, a similar implementation to the code you’ve provided would likely look something like this (potentially missing an extra using for the appropriate namespace from the integration):

using Godot;

public partial class YourCustomClass : Node2D
{
    var instance;
    public override void _Ready()
    {
        instance = FMODRuntime.CreateInstancePath("event:/Crypt");
        instance.start();
    }

    public override void _Process(double delta)
    {

    }
}

However, this assumes the C# bindings are the same, that the integration code and namespaces like FMODRuntime are the same in C# or even exist at all. If the integration doesn’t support the use of C#, then I’m afraid I cannot be of any help.

It’s worth noting, however, that if the integration doesn’t support the use of C#, you should still be able to use the FMOD Engine’s existing C# wrapper (i.e. the same one that is used by our official Unity Integration) with a Godot mono build.

Hi, thank you for your response- using the help you’ve provided I’m currently receiving this error:

C:\Users\User\Documents\GitHub\metroidvania\Crypt.cs(6,2): The contextual keyword ‘var’ may only appear within a local variable declaration or in script code

I’m assuming this is because “var” is not defining the type of variable “instance” should be, however I’m not sure what type to use. Sorry if I’m not understanding, I’m not a coder and am still learning a great deal.
Thanks!

My apologies - instance should be of the type FMOD.Studio.EventInstance, though you can shorten it to just EventInstance by putting using FMOD.Studio; at the top of the file alongside using Godot;.