C# question: What is the equivalent to GDScript's "func _input(event)"?

Godot Version

v4.2.1.stable.official [b09f793f5]


How should input events be handled in a C# class, as with _input in a GDScript class? I would have expected public override void _Input(InputEvent event) { ... } to work, but when I try this I get an “Identifier expected” syntax error. Which is a very unexpected error, since the syntax looks to me like it should be valid?

event is a dedicated C# keyword. You need to rename your parameter.


As stated before, event is a reserved keyword.

Just for fun:

You can still use it by prefixing the name with the @ character.

Your code would look like

public override void _Input(InputEvent @event) {
    var event_button = @event as InputEventMouseButton;

    if(event_button is not null) {
       // TODO

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.