Godot Version
4.2.1
Question
Hi first of all
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:
@tool
extends EditorPlugin
var editor_inspector = preload("res://addons/testjsonselect/jsonselect_editorplugin.gd")
func _enter_tree():
editor_inspector = editor_inspector.new()
add_inspector_plugin(editor_inspector)
func _exit_tree():
# Clean-up of the plugin goes here.
remove_inspector_plugin(editor_inspector)
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":
print(object)
object.test()