godot-docs icon indicating copy to clipboard operation
godot-docs copied to clipboard

It is not clear how EditorResourcePicker should be used

Open eh-jogos opened this issue 3 years ago • 5 comments

Your Godot version: Godot 3.4.4.stable

Issue description: The documentation for EditorResourcePicker states that:

Note: This Control does not include any editor for the resource, as editing is controlled by the Inspector dock itself or sub-Inspectors.

But it doesn't explain or give an example of how to make the inspector or sub-inspector edit the resource in question, and specially how to open the resource when clicked.

I was able to figure out I had to connect to the resource_changed signal in the parent EditorProperty to be able to actually edit the property, and that wasn't so hard.

Then I figured to open the resource in the inspector, I needed to use the resource_selected signal from EditorResourcePicker and connected it to a function in the parent EditorProperty.

In the connected function I call:

emit_signal("resource_selected", get_edited_property(), resource)

This is the resource_selected signal from EditorProperty and it does open the Custom Resource in the editor like this: image

But I can't open it as a sub-inspector, like I can when I just export it as a regular Resource. The documentation for this resource_selected signal is also a bit confusing, it says:

resource_selected(path: String, resource: Resource) If you want a sub-resource to be edited, emit this signal with the resource.

But what is path supposed to be? I'm passing EditorProperty.get_edited_property() to it, but it doesn't really seem to matter, as it works exactly the same way whatever I pass to it. I can leave it as an empty string or pass complete garbage to it like this:

emit_signal("resource_selected", "heuhueh", resource)

And it will still work exactly the same.

The only place in the documentation I found any mention of sub-inspectors was the signal object_id_selected(property: String, id: int) from EditorProperty, but if I do:

emit_signal("object_id_selected", _property_path, resource.get_instance_id())

I get this error:

error core/io/packet_peer.cpp:254 - Condition "peer.is_null()" is true. Returned: ERR_UNCONFIGURED So I guess I'm clearly using it wrong.

Anyway, I'm really lost here.

URL to the documentation page (if already existing): EditorResourcePicker EditorProperty signals

eh-jogos avatar Jul 03 '22 07:07 eh-jogos

You simply cannot open a sub-inspector, only a dedicated inspector. To be able to have a sub-inspector, the EditorInspector itself must be exposed, and it isn't.

YuriSizov avatar Jul 03 '22 10:07 YuriSizov

You simply cannot open a sub-inspector, only a dedicated inspector. To be able to have a sub-inspector, the EditorInspector itself must be exposed, and it isn't.

Oh Okay! That explains it, thanks for the quick reply! Is this also valid for Godot 4? Or is this a Godot 3.x limitation? (Though I guess with native support for exporting Custom Classes coming in Godot 4 this won't be an issue)

Also, the resource_selected signal from EditorProperty, am I using it correctly even though the "path" parameter doesn't seem to matter? Should I be just using it with an empty string instead of get_edited_property()?

eh-jogos avatar Jul 03 '22 11:07 eh-jogos

I just finished implementing what I wanted but found other errors that I'm not sure are documentation only, so I created an issue on the engine repository as well: https://github.com/godotengine/godot/issues/62679

eh-jogos avatar Jul 03 '22 15:07 eh-jogos

Is this also valid for Godot 4?

Yeah, we didn't expose the inspector widget anywhere yet. I think we should, but we haven't discussed it. We already reuse it in several places of the editor UI, so it's already pluggable.

Also, the resource_selected signal from EditorProperty, am I using it correctly even though the "path" parameter doesn't seem to matter? Should I be just using it with an empty string instead of get_edited_property()?

It should be the path to the property (a qualified property name, if you will, with all the slashes if it's grouped). Using get_edited_property() is correct and what the editor itself does. Path is used internally to actually set the property of the object. If it's invalid, it shouldn't set.

YuriSizov avatar Jul 03 '22 15:07 YuriSizov

Marking as new page because I think adding a tutorial about it makes sense for the editor plugins section. This widget probably has more use in custom plugins that you make for your project rather than inspector plugins, so that would be the angle I'd use for the article.

YuriSizov avatar Jul 03 '22 15:07 YuriSizov

Hey!

You mentioned that you figured out a way to make it work even if having the dock be an external window. Would you mind mentioning the way you made it? So far i can open the resource itself, but it never saves, when i go back the EditorResourcePicker is empty.

Cheers!

EpsylonPT avatar Nov 14 '23 15:11 EpsylonPT

@EpsylonPT if you were refering to my comment, to be honest I don't remember anymore as it's been more than an year and I ended up migrating to Godot 4.x shortly after so never used this much in practice.

The code that worked is here if you want to check it out: https://github.com/eh-jogos/eh_Utilities/tree/main-3.x/addons/eh_jogos.utilities/custom_inspectors/custom_resource

If it's not saving my guess is that you're not emitting some signal in the InspectoProperty with the property path and the added resource, like here: https://github.com/eh-jogos/eh_Utilities/blob/b24682ab13661ad3ed39792db2c4cd3b7fa8a05c/addons/eh_jogos.utilities/custom_inspectors/custom_resource/custom_resource_property.gd#L110-L123

Hope this helps.

eh-jogos avatar Nov 15 '23 14:11 eh-jogos