[Solved] C# InputEventMouseMotion.Relative not defined

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By IAmOnFire

[Solved trying to delete this post]

inputEvent is InnputEventMouseMotion eventMouseMotion

the Mouse’s relative variable is stored in eventMouseMotion not inputEvent


Hi All, I can’t seem to access the variable “Relative” in an InputEventMouseMotion

Things I’ve tried:

  • Casting the inputEvent to InputEventMouseMotion
  • inputEvent.GetType() returns “Godot.InputEventMouseMotion”
  • inputEvent.GetType().GetFields() - returns an Empty array
  • different iterations of “Relative” (relative, Relative, GetRelative())

Code: (I Could not figure out how to properly format my code)

Thanks,
(will keep searching) - currently trying to print out all variables and methods of the object.

:bust_in_silhouette: Reply From: jgodfrey

Untested, but…

public override void _UnhandledInput (InputEvent ev) {
    if (ev is InputEventMouseMotion) {
        InputEventMouseMotion m = (InputEventMouseMotion) ev;
        // here, you can reference "m.Relative.x"... 
    }
}

This will work!

public override void _UnhandledInput (InputEvent event) {
    if (event is InputEventMouseMotion ev) {
        //...
    }
}