Inspector Plugins

Introduction

Godot 3.1 comes with a new inspector. Adding plugins to it is now possible.

This tutorial will explain the process.

Inspector Plugin

This short tutorial will explain how to make a simple value editor. Create an EditorInspectorPlugin first. This is needed to initialize your plugin.

GDScript

  1. # MyEditorPlugin.gd
  2. extends EditorInspectorPlugin
  3. func can_handle(object):
  4. # if only editing a specific type
  5. # return object is TheTypeIWant
  6. # if everything is supported
  7. return true
  8. func parse_property(object,type,path,hint,hint_text,usage):
  9. if (type==TYPE_INT):
  10. add_custom_property_editor(path,MyEditor.new())
  11. return true # I want this one
  12. else:
  13. return false

Editor

Here is an editor for editing integers

GDScript

  1. # MyEditor.gd
  2. class_name MyEditor
  3. var updating = false
  4. func _spin_changed(value):
  5. if (updating):
  6. return
  7. emit_changed( get_property(), value )
  8. func update_property():
  9. var new_value = get_edited_object()[ get_edited_property() ]
  10. updating=true
  11. spin.set_value( new_value )
  12. updating=false
  13. var spin = EditorSpinSlider.new() # use the new spin slider
  14. func _init():
  15. # if you want to put the editor below the label
  16. # set_bottom_editor( spin )
  17. # else use:
  18. add_child( spin )
  19. # to remember focus when selected back
  20. add_focusable( spin )
  21. spin.set_min(0)
  22. spin.set_max(1000)
  23. spin.connect("value_changed",self,"_spin_changed")