2D Scene Paint based plugin

Godot Version

4.7

Question

How do i check if the scene paint brush is selected and set the current scene. I have all the rest of my plugin set up

Don’t know exactly what you’re saying, but do you mean to check whether the developer currently is working in the new scene paint mode?

You can hook into the button controls of Godot and check whether it is toggled.

It is a bit hacky, admittedly.

Here is the way I look up the button for ‘Select Mode (Q)’:

func _get_select_mode_button() -> Button:
	if is_instance_valid(select_mode_button):
		return select_mode_button
	else:
		select_mode_button = (
			EditorInterface.get_editor_viewport_2d().find_parent("*CanvasItemEditor*")
					.find_child("*Button*", true, false)
		)
		return select_mode_button

You can dump the control nodes of the entire editor with a print in a recursive function to find the button you need:

@tool
## (can be any Node as long as it's a tool)
extends EditorPlugin 

func _enter_tree():
	# print root
	_dump_interface(EditorInterface.get_base_control(), 2)  

## Will print the tree (use with care, because your plugin will probably not be forward compatible across versions)
func _dump_interface(n : Node, max_d : int = 2, d : int = 0) -> void:
	if n.name.contains("Dialog") or n.name.contains("Popup"):
		return
	print(n.name.lpad(d + n.name.length(), "-") + " (%d)" % [n.get_child_count()])
	for c in n.get_children():
		if d < max_d:
			_dump_interface(c, max_d, d + 1)

Seeing which scene is selected by the brush you’ll have to figure out by yourself. That may take a bit of staring at the c++ source code of the engine, or may just be by reading out some value of the control node showing the currently selected scene.

Sometimes stuff is simply not exposed for plugin building (yet).

Im making a plugin to add palettes to the scene brush. i was told on the suggestion page that they originally were gonna have a panel but decided to keep it simple so im just porting over the menu from a scene brush tool i made in 4.6

Was my answer helpful? I wasn’t sure if this is what you wanted to do.

Ill have to check when i get home if im able to set the currently selected scene just by changing the ui component but for getting if youre using the scene paint mode it should work

I still haven’t found the route to getting the current grid-snap configurations myself​:grin:

Oh dang i was gonna add holding shift to unsnap or snap depending on your config

Actually i didn’t realize this was already in the scene painter. The setting scenes is unexposed and i tried workarounds so ill just wait till they expose it.