How to toggle gizmos in 2D

Godot Version

4.2

Question

Hi! In 3d scenes you can toggle visibility of several gizmos, like this:

Is there a similar option in 2D? For disabling collision shapes temporarily, for example, it would be very useful.

Thanks!

No, there’s no similar feature in 2D. You can write a small plugin that does that though.

For example:

@tool
extends EditorPlugin


var toggle_button:CheckButton


func _enter_tree() -> void:
	# A button to toggle on and off the collision shapes 2D nodes
	toggle_button = CheckButton.new()
	toggle_button.text = "Show CollisionShapes2D"
	toggle_button.button_pressed = true
	toggle_button.toggled.connect(func(toggled:bool):
		var collision_shapes = EditorInterface.get_edited_scene_root().find_children("*", "CollisionShape2D", true, false)
		for shape in collision_shapes:
			shape.visible = toggled
	)
	add_control_to_container(EditorPlugin.CONTAINER_CANVAS_EDITOR_MENU, toggle_button)



func _exit_tree() -> void:
	# Clean up nodes
	if is_instance_valid(toggle_button):
		remove_control_from_container(EditorPlugin.CONTAINER_CANVAS_EDITOR_MENU, toggle_button)
		toggle_button.queue_free()
		toggle_button = null

Result:

1 Like

Thanks a lot for your answer!