0 votes

Hello

I am trying to write an editor plugin that will draw a custom grid over the editor viewport. As per a previous question, I am basing this off of the code in tilemap_editor_plugin.cpp. I have gotten to the code below, but the forward_draw_over_viewport function never get's called. The naming of this function isn't quite the same as in the cpp class, so I may be overriding the wrong function. However, the other functions within EditorPlugin don't seem to implement this functionality. Am I looking in the wrong place, or do I need to do something else to trigger the update?

tool
extends EditorPlugin


func _enter_tree():
    print("Entered")
    update_overlays()

func _exit_tree():
    print("Exited")

func forward_draw_over_viewport(overlay):
    overlay.draw_line(Vector2(), Vector2(1000, 10000), Color(1, 0, 0), 1.0, true)

Thankyou in advance for any other help you can give.

in Engine by (19 points)

1 Answer

0 votes

You have to override handles virtual method to activate drawing, and use forward_canvas_draw_over_viewport() instead of forward_draw_over_viewport(). If drawing doesn't work immediately, try calling update_overlays().

(Godot 3.2.4)

tool
extends EditorPlugin

var points = [Vector2(90, 100), Vector2(100, 230), Vector2(250, 200)]

func _enter_tree():
    update_overlays()

func handles(object):
    # To trigger `forward_canvas_draw_over_viewport`
    return object is Node2D

func forward_canvas_draw_over_viewport(overlay):
    overlay.draw_colored_polygon(points, Color.white)
by (1,356 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.