Event.button_index no longer works

Godot Version

4.3

Question

I’m following a video series and I’m trying to use the following line:

if event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT

seems event.button_index is no longer a valid method. chatgpt told me to try button_index, that doesnt work either. what is the correct syntax for 4.3?

thank you.

Hmm, I think it works, it is just the autocomplete in the editor doesnt show it for some reason.

If you’re using a function like _input, the event paramenter will be typed as InputEvent class and in this class the button_index property doesn’t exist (this is a property, not a method). If you want to have the autocompletation in this case you need cast the event parameter as InputEventMouseButton (this class has the button_index property):

# The (event as InputEventMouseButton) will treat the event parameter 
# as from the InputEventMouseButton class, so in this case will provide
# the correct autocompletation
if event is InputEventMouseButton and (event as InputEventMouseButton).
2 Likes

Ah thank you. Thank is very helpful going forward!