Can I use match event: InputEventMouseButton? Is it equivalent to the is operator?

Godot Version

4.2

Question

I have seen that event use is, is that supposed to work with match?

match(event):
    InputEventMouseButton:
        print('something')

Apparently this code doesn’t generate error.

What am I doing wrong?

Hey!

I couldn’t find a way to make it work with the simple match statement.
I did found a workaround though:

func _input(event):
	match event.get_class():
		"InputEventKey":
			print("Key Pressed: ", event.keycode)
		"InputEventMouseButton":
			print("Mouse Button Pressed: ", event.button_index)
		_:
			print(event.get_class())

Hope that helps!

Thanks

Also in term of performance, I am not sure it’s adequate but I haven’t profiled.

I would prefer using if and is instead.

1 Like