Skip to content
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

Display compatible custom resources when editing a Resource property in the inspector #34828

Conversation

Phischermen
Copy link
Contributor

Fixes #31591
When the user adds a custom resource via a GDScript plugin, their resource will now be displayed in the pop up menu when editing a compatible Resource property.

One limitation of my solution however is that it does not display children of custom resources. The solution I have in mind for that issue is a bit messy: find children of each custom type already found, and then find their children until no more children are found.

I'm actually not sure how to make a custom resource that derives from another custom resource through a GDScript plugin, so I can't set up a test project right now. If anyone knows how, I'd appreciate some guidance.

@Phischermen
Copy link
Contributor Author

I rebased recently, and it's still working!

@Phischermen
Copy link
Contributor Author

I spoke a little too soon. After some testing, I found out that although compatible resources appear in the list, they do not instance yet. I'll turn this PR into a draft instead and continue working on it.

@Phischermen Phischermen marked this pull request as draft May 27, 2020 05:53
@Phischermen Phischermen force-pushed the display-all-valid-resources branch from e0908e1 to 389f9c7 Compare May 28, 2020 19:49
@Phischermen
Copy link
Contributor Author

Phischermen commented May 28, 2020

My current solution works on the 3.2 branch, but now an error message is printed when a custom resource is instantiated through the inspector.
" Cannot get class 'CustomResource'. "
This error is not printed when instantiating a custom resource through the file system.

I'm having difficulties testing this on the 4.0 branch due to its instability, but I'm certain my solution isn't working there. I'm able to instance a custom type with this function:

obj = EditorNode::get_editor_data().instance_custom_type(intype, b);

But it must not be what I think it is, because it cannot cast to Resource:

Resource *resp = Object::cast_to<Resource>(obj); //cast fails, and thus resp is null
ERR_BREAK(!resp);

Hopefully I can figure it out after some debugging.

Edit:
My PR is not causing the issues I'm having on the 4.0 branch. Custom resources just don't seem to work period.

@Phischermen
Copy link
Contributor Author

I got it working on 3.2 without errors! There is however one edge case I've found. Some resources have sub-resources, like materials in meshes for example. For some reason, the base_type is in reverse order for sub-resources, meaning I can't use get_slice() to reliably get the base type, and thus can't reliably instance the custom resource.

@Phischermen Phischermen force-pushed the display-all-valid-resources branch 2 times, most recently from eff423a to 90d68d4 Compare June 2, 2020 04:09
@Phischermen
Copy link
Contributor Author

I fixed my edge case by not using get_slice(). Now, I record what base resource the custom resource inherits and instance that directly. If this passes the checks, I'll rebase and make this ready to review.

@Phischermen Phischermen force-pushed the display-all-valid-resources branch 3 times, most recently from 36d9bc5 to 7f46a09 Compare June 3, 2020 19:51
@Phischermen Phischermen marked this pull request as ready for review June 3, 2020 19:52
@Calinou Calinou added this to the 4.0 milestone Jan 5, 2021
…e types

Fix issue regarding the display of resources when editing resource properties.
@Phischermen Phischermen force-pushed the display-all-valid-resources branch from 7f46a09 to 3b7b02d Compare July 15, 2021 17:26
@Phischermen
Copy link
Contributor Author

I rebased recently, and have moved functionality to the new EditorResourcePicker class. Although I can successfully populate the menu with the appropriate items, I can not instantiate them without crashing the editor. It looks like #48201 fixes the crash I'm experiencing, but my PR will likely need to be updated again once #48201 is merged.

@YuriSizov YuriSizov requested review from a team August 24, 2021 22:37
@akien-mga
Copy link
Member

This seems closely related to #48201 and related PRs, CC @willnationsdev. I'm assuming it might be superseded by some of the newer/recently updated PRs but it would be good to check.

@TechnoPorg
Copy link
Contributor

I believe this was superseded by #62413, and the linked issue has already been resolved.

@Calinou
Copy link
Member

Calinou commented Oct 2, 2022

Superseded by #62413. Thanks for the contribution nonetheless!

@Calinou Calinou closed this Oct 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Display all compatible resources when creating one in the resource slot
4 participants