+1 vote

I have a editor tool script that changes the in-game camera position on the map...

I would also like to add functionality to change the Editor's viewport position... where its looking in the map.

To quickly jump around to different pre-set locations.

Only other workaround i can think of is to place a bunch of empty Position3Ds around the map then somehow call the Godot hotkey to center focus on an object?


Godot version 3.3
in Engine by (19 points)

1 Answer

+1 vote

FHeres a hacky workaround I did using a Plugin... there may be a more elegant solution but for now this works.

## place this code in a background plugin in the editor
# Then place 4 Spatials around your map with names "NavPoint1" , "NavPoint2" etc..

func _unhandled_input(event):

    if event is InputEventKey:
        if event.pressed and event.scancode == KEY_3:
        if event.pressed and event.scancode == KEY_4:
        if event.pressed and event.scancode == KEY_5:
        if event.pressed and event.scancode == KEY_6:

func go_to_node(nodeName):
    var es : EditorSelection = editor_interface.get_selection()
    if es == null:
        print("cant initialize EditorSelection, returning")
    var node_to_nav_to = get_tree().get_edited_scene_root().find_node(nodeName)
    if node_to_nav_to == null:
        print("cant nav to node")

    print("simulating F Key")

func simulate_key(which_key ):
    print("simulating key %s" % which_key)
    var ev = InputEventKey.new()
    ev.scancode = which_key
    ev.pressed = true
by (19 points)

This is hacky as hell, but it works. Thank you!

In my experience, to restore the selection afterwards you'll have to use call_deferred()

func go_to_node(node_name):
    # aforementioned code to select a node
    call_deferred(restore_selection, initial_node)

func restore_selection(initial_node):  

This way you can focus wherever you need, and then resume your work where you left off.

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.