Can I extend the InputEvent?

Godot Version

v4.3.stable.mono.official [77dcf97d8]

Question

Hello, I want to extend a custom InputEvent from InputEventMouseMotion so I can have a rotation variable that controls the rotation of the cursor (a sprite replace the cursor). So I have the follow class:

# inputEventRemoteMotion.gd
class_name InputEventRemoteMotion extends InputEventMouseMotion

var rotation: float = 0.0 

Then in one of my other script I can emit this custom event by

var motion = InputEventRemoteMotion.new()
motion.position = Vector2(x, y)
motion.rotation = 45
print(motion is InputEventRemoteMotion)  # this  print true
Input.parse_input_event(motion)

However in my another script handles this event:

const InputEventRemoteMotion = preload("res://scripts/inputEventRemoteMotion.gd")
...
func _input(event: InputEvent) -> void:
	if event is InputEventRemoteMotion:
		print("InputEventRemoteMotion")
    elif event is InputEventMouseMotion:
		print("InputEventMouseMotion")

The “InputEventRemoteMotion” is never printed but “InputEventMouseMotion” is always printed, how can I check if the event is “InputEventRemoteMotion” in this case? Thanks.

It’s not possible as Godot will internally modify the input event.

Why do you need to attach the rotation to the event anyway? Can’t you use an autoload for example?

If you still want to attach extra information to the event you can use Object.set_meta() as long as the node that sets the meta uses _input() and the node that gets the meta uses _unhandled_input(). More information about how the input event system works here

Oh, thank you for the explanation. I have a background process that generates user input (cursor movement, presses, and cursor rotation) for Godot. I thought rotation was also a type of user input, so it would be better to include it in the InputEvent and process it together with the motion.