+3 votes

Godot version: 3.1 Beta 10 e930fb9

OS/device including version: OSX Mojave 10.14.3

TL;DR. Can anyone provide an example of using EditorInspectorPlugin and EdtiorProperty to implement custom inspector?

I'm was trying to implement a custom editor inspector for a custom resource class, in which one exported property depends on another. Goal is to modify the inspector for this resource to display the dependent property as read-only and to update it's value whenever the value of another property has changed.
I have tried to use combination of EditorInspectorPlugin and EditorProperty to achieve this. But I found out that none of the EditorProperty signals (e.g. property_changed ( String property, Nil value) and others) actually get fired. In addition none of the properties like read-only seem to work either.

Am I missing something? Or are these features not fully implemented yet?

An example code I have tried to implement:

# CustomResource.gd
extends Resource
class_name CustomResource

export (int, 1, 100) var agility = 1 
export (int) var speed = 2 * agility    

# custom_editor.gd
tool
extends EditorPlugin

const CustomInpsectorPlugin = preload("res://addons/custom_editor/CustomInpsectorPlugin.gd")

var plugin

func _enter_tree():
     plugin = CustomInpsectorPlugin.new()
    add_inspector_plugin(plugin)

func _exit_tree():
    remove_inspector_plugin(plugin)
    plugin.free()

# CutomInspectorPlugin.gd
tool
extends EditorInspectorPlugin 

func parse_begin (object):
    agilityControl = EditorProperty.new()
    agilityControl.read_only = true    # this doesn't have any effect
    agilityControl.connect("property_changed", self, "_on_property_changed")
    add_property_editor("agility", agilityControl)

func can_handle (object):
    if object is CustomResource:
        return true
    return false

func _on_property_changed(property, value):
     # This function is never called
    print("on property changed: ", property, ", ", value)
in Engine by (15 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.