-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Added NodePath Hint to specify a list of acceptable Node Types #38402
Conversation
This seems pretty useful, is it possible to use static references to the class though instead of strings? |
It seems perfectly possible in GDScript. Having a static reference to the class in C# doesn't seem trivial, because of the way Export Hints are defined in C#. Also, because of the cross-language interoperability it may make a lot of sense to use strings (or at least to have both options). I would suggest to include this implementation and possibly improve over it later to also support static references. My reasons to suggest this are the following:
I also understand that this functionality, once merged, should not change drastically breaking backward compatibility. So I'm open to suggestions. What do you think? |
so wait C# already has a type system are you saying we aren't going to be able to export custom node types? what would be ideal would something like.. |
C# is missing a few custom export modes so don't worry about this. At some point I'll have to implement them. |
I dislike this string based implementation as in large projects it can become tedious to have to list a base type as a string and all of its inherited types, the way I am implementing it in a WIP PR that would fully resolve godotengine/godot-proposals#1048 is passing any |
Hello @creikey I agree with you that the string approach is far from ideal but if you take a look at the code you will see that my main goal was:
|
@fejnartal The native type works when matching however scripts that extend from other scripts ( fairly common in bigger games ) are not recognized from the base script e.x: adding "CustomClass" as an export hint in the nodepath assign dialog |
Hi @creikey thank you for testing that and answering. The solution will still be based on strings I'm afraid. |
Judging by the last screenshot in this article, exporting specific node types in NodePath will be possible in Godot 4.0: |
Thank you @Calinou godotengine/godot-proposals#828 I guess it won't hurt if I can try to add missing functionality identified by @creikey to this PullRequest since it may be a good starting point for other developments even if this proves to be insufficient or not as useful as I though it would be. |
I currently don't have a proper development environment. at hand I will try to compile and test this change myself as soon as I have one. But just in case any of you have the time and interest to try to test it yourself I have added a new check that may work for custom types' subclasses too as @creikey has suggested. https://docs.godotengine.org/es/stable/classes/class_classdb.html#class-classdb-method-get-inheriters-from-class
I currently don't have a proper development environment at hand. I will try to compile and test this change myself as soon as I have one. |
The original repository has been deleted and there's another similar PR for that feature #39155, so I'll close this one. |
Added the ability to specify a list of valid types when exporting a NodePath (also works for CustomTypes)
This functionality was already working in VisualScript so I simply filled the gaps to make it work in GDScript, and C#.
By specifying a list of valid types the NodeSelector dialog will only allow selecting nodes of those types. Other nodes in the tree will still appear but will be disabled (grayed out.)
It has been tested to also work for NodePath Arrays in GDScript.
It is not working in C# for IEnumerable types though.
However it seems that export hints are never applied for C# IEnumerable types (it appears to be a bug and is not in the scope of this change.)
HOW IT WORKS:
In GDScript:
(Simply enumerate the type of the Nodes that can be selected)
export(NodePath, "Button", "CustomType") var nodepath
You are not forced to specfify any type. This still works:
export(NodePath) var nodepath
In C#:
[Export(PropertyHint.NodePathValidTypes,"Button,CustomType")] private Node2D nodepath;
(Notice that in C# the list of valid types must be encoded as a single String)
Some requests related to this change: