Trying to get access to functions and variables of an object in a EditorInspectorPlugin

Godot Version



Hi first of all :slight_smile:
I’m trying to solve this since days and I don’t find any related help about this online so I hope someone here can point me in the right direction.

What I trying to to:

  • I try to have some Data (like different Text fields") in an external JSON file.
  • I want to create a plugin that will display the content of the JSON file and give the user the possibility to select some fields of the JSON
  • after the selection, the selected text values should be saved in a different property/resource of the object in which the JSON was selected.

So that I can have many text blocks in one JSON file but only use some of them for different use cases.

What I did so far:

  • I created a new EditorPlugin.
  • I created a new EditorInspectorPlugin
  • I load the EditorInspectorPlugin in die EditorPlugin by using “add_inspector_plugin”
  • I created a new class “TestObject” to limit the EditorPlugin action onto objects of this type.
  • I check in the “_can_handle” and “_parse_property” callbacks if the type of object and name of the property is the one that I want my magic to happen.

The Problem:
So far so good. I can print the object from the _parse_property parameters and it looks correct. I can create a new Control of type EditorProperty and add it to the Inspector. In it I can even use “get_edited_object()[get_edited_property()]” to check if the property is null or if it is already set to anything.

What I cannot do is accessing any function or variable of the “get_edited_object”. For example I created a function called “test” in my new TestObject class but when I try to call it in “_parse_property” of the EditorInspectorPlugin I just get an Error:

Invalid call. Nonexistent function 'test' in base 'Node3D (TestObject)'.

Can someone give me any explanation what I am missing? Am I using EditorPlugin wrong?

Code of the EditorPlugin:

extends EditorPlugin

var editor_inspector = preload("res://addons/testjsonselect/")

func _enter_tree():
	editor_inspector =

func _exit_tree():
	# Clean-up of the plugin goes here.

Code of the EditorInspectorPlugin:

extends EditorInspectorPlugin

# only for test objects
func _can_handle(object):
	return object is TestObject

func _parse_property(object, type, name, hint_type, hint_string, usage_flags, wide):
	if name == "data":

Your EditorInspectorPlugin needs to be a @tool script too.

And I’m not sure but it’s quite probable that the script that has the test() function also needs to be a @tool script.

1 Like

Interesting… Everything else (like adding custom UI elements in the Inspector Plugin works fine) The script is also executed. I can see prints like expected. It not makes sense for me why this should be the issue here.

I added the @tool to both the EditorInspectorPlugin and the TestObjectcass… and reloaded the project (very important!) now it works. I still don’t fully understand why this is necessary but thank you very much for pointing this out :slight_smile:

Only @tool scripts can run in the editor. If the script is not a @tool script or extends a script that isn’t a @tool script or access some object which script isn’t a @tool script it will fail. It’s explained here Running code in the editor — Godot Engine (stable) documentation in English

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.