How to get forward_canvas_draw_over_viewport to be called?

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

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.

:bust_in_silhouette: Reply From: Xrayez

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)