0 votes


I'm trying to get mouse coordinates in tool mode for an editor script.

My problems are:

1) Input seems to have removed Input.getmousepos()
2) _input callback is not called in tool node.

Is there any other solution?


in Engine by (44 points)

I don't know for in-scene tool scripts, but you can get the input from an editor plugin instead: http://docs.godotengine.org/en/latest/classes/class_editorplugin.html#class-editorplugin-forward-input-event

2 Answers

+2 votes
Best answer

1) You're right, but you can get mouse position from InputEvent (more precisely InputEventMouseButton) in _input or _input_event callback.

2) It is working for me. If you want to receive _input callback, you have to first call set_process_input(true). The alternative is to use _input_event. In that case, you don't have to call set_process_input(true), but it's working only for Control nodes.

by (810 points)
selected by
+1 vote

I solved the problem by adding a addon/plugin dock. "Output" is a label in the dock, that displays the mouse position.

If the current scene has a Position2D node, it will be placed at the mouse position and the displayed vector will be taken from there.

func _enter_tree():

func _input(event):
    var mp = get_tree().get_edited_scene_root().get_global_mouse_pos()

    #use Position2D if available
    get_tree().get_edited_scene_root().get_node("Position2D").set_pos(mp + Vector2(0, -40))
    var cursorpos = get_tree().get_edited_scene_root().get_node("Position2D").get_pos()
        cursorpos = cursorpos.snapped(Vector2(8, 8)) #snap to grid
        get_node("Output").set_text(str( cursorpos ))

It somehow works but depends strongly on the zoom level in the editor. So far, I've not found a way around that.

by (185 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.