-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose EditorInspector::get_edited_object
to GDScript
#81425
Expose EditorInspector::get_edited_object
to GDScript
#81425
Conversation
EditorInspector::get_edited_object
to GDScript
Can you provide an example of how it would be used? |
My use case is detecting when the user changes an exported This is the snippet of code where I'm using func __on_godot_editor_inspector_property_edited(_p_property : String) -> void:
var edited_object : Object = m_editor_inspector.get_edited_object()
if editor_plugin_handles(edited_object):
editor_plugin_edit(edited_object)
editor_plugin_make_visible(true)
else:
# We cannot handle the current object. Disable the BehaviorTreeEditor.
editor_plugin_make_visible(false) In the snippet of code above the custom type my plugin can handle is a stateless
I'm probably missing another practical few use cases for I suppose |
You can get the same object reference from |
What is pending on this? |
@tool
extends EditorInspectorPlugin
var plugin:EditorPlugin # assigned by the plugin itself on creation
func _parse_property(object: Object, type: Type, name: String, hint_type: PropertyHint, hint_string: String, usage_flags: PropertyUsageFlags, wide: bool) -> bool:
if not(object is BehaviorTree): return false # Handle your object type, I guess plugin.editor_plugin_handles() works too
plugin.editor_plugin_edit(edited_object)
plugin.editor_plugin_make_visible(true) # hope none of these calls EditorInterface.edit
return true # Is your object type, but you should return false if you don't want to override editor default node
What would be the difference between listening for |
The object passed through I'm not sure how your script solves the issue I've explained. Any object could have an exported resource set to |
This comment was marked as off-topic.
This comment was marked as off-topic.
@RadiantUwU Please don't bump PRs without contributing significant new information. Use the 👍 reaction button on the first post instead. |
UPDATE: There is now a valid workaround for godot 4.1+ @tool
extends EditorPlugin
var currently_selected_objects:Array[Object]
var resource_sel:=false
func _edited_object_changed():
if resource_sel:
resource_sel = false
else:
currently_selected_objects.clear()
currently_selected_objects.append_array(get_editor_interface().get_selection().get_selected_nodes())
print(currently_selected_objects)
func _select_resource(resource: Resource):
currently_selected_objects.clear()
currently_selected_objects.append(resource)
resource_sel = true
func _property_edited():
print(currently_selected_objects,get_editor_interface().get_inspector().get_selected_path(),currently_selected_objects[0].get_indexed(get_editor_interface().get_inspector().get_selected_path()))
func _enter_tree():
# Initialization of the plugin goes here.
get_editor_interface().get_inspector().property_edited.connect(_property_edited)
get_editor_interface().get_inspector().resource_selected.connect(_select_resource)
get_editor_interface().get_inspector().edited_object_changed.connect(_edited_object_changed,CONNECT_DEFERRED)
func _exit_tree():
# Clean-up of the plugin goes here.
get_editor_interface().get_inspector().property_edited.disconnect(_property_edited)
get_editor_interface().get_inspector().resource_selected.disconnect(_select_resource)
get_editor_interface().get_inspector().edited_object_changed.disconnect(_edited_object_changed) |
Nevermind, works only on nodes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from the doc correction, this should be okay as it only exposes a method.
8742b1e
to
c844988
Compare
Thanks! |
I'm making an EditorPlugin for a
Resource
subclass and while it's possible to extract what property has been modified to using theproperty_edited
signal, the plugin needs to know what the new value of the property is in order to set some internal flags. ExposingEditorInspector::get_edited_object
allows the EditorPlugin to query the value of the property withObject.get(property)
within aproperty_edited
callback.Production edit: Closes godotengine/godot-proposals#7789