Help with EditorInspectorPlugin on Resource

Godot Version

4.3

Question

Hello, I’m attempting to create a custom button for my custom Resource Script.

I have the plugin structure setup, and I can see logs of my plugin loading, however, I do not see my can_handle function being called. My Inspector does not look any different, and I think my code looks similar to other examples in the documentation, and examples online. Any help would be appreciated:

To be clear, the item_data is a script that is placed on my resource. I can see other inspector fields populated for my exported variables.

@tool
extends EditorPlugin

#const ItemIDInspectorPlugin = preload("res://addons/item_id_tool/item_id_inspector.gd")

var inspector_plugin: ItemIDInspectorPlugin

func _enter_tree():
	inspector_plugin = ItemIDInspectorPlugin.new()
	add_inspector_plugin(inspector_plugin)
	print("Item ID Plugin loaded")

func _exit_tree():
	remove_inspector_plugin(inspector_plugin)
	print("Item ID Plugin unloaded")


class ItemIDInspectorPlugin:
	extends EditorInspectorPlugin

	func can_handle(object) -> bool:
		print("can_handle called on:", object)
		if object is Resource and object.get_script() != null:
			return object.get_script().resource_path.ends_with("item_data.gd")
		return false

	func parse_begin(object):
		var button := Button.new()
		button.text = "Assign New ID"
		button.pressed.connect(func():
			object.generate_new_id()
			print("New ID assigned:", object.id)
		)
		add_custom_control(button)

The function you need to implement is _can_handle(), not can_handle()

1 Like

Oh my goodness. Thank you I must have read over the documentation 10 times, but never caught my mistake. Thank you!