-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
Ability to export Node types #7821
Comments
This would be very cool to have indeed... |
From #7846:
|
Hmm but that would mean exporting a NodeRef which is not that handy (because type info is lost), unless that's how we would implement it behind-the scenes? Also, self-updating references when nodes are moved in the editor is more like something the editor should care about. It could be fixed by designing Nodes so they are References but it would go deeper in Godot's design. |
@Zylann No it doesn't mean exporting a NodeRef, though we can do something like |
I'm not fan of |
Wouldn't it be a better idea to enable NodePath objects to handle re-acquiring the new path to any repositioned nodes it was previously assigned to by having it connect an acquisition method to the node's |
@willnationsdev you can't do that, |
I do agree that exporting with the name of the node type directly is preferable to supplying it as a second argument after |
What about making |
@neikeq That would probably be a good idea for initialization via code. Isn't there another problem here in that Variants are flexible enough to accept any sort of assignment and will just adapt the type rather than performing some sort of validation on the type? I mean, even if you do |
@neikeq that would solve the use case of linking when game starts but it would not solve the fact I still need all this boilerplate in tool mode |
Having skimmed the comments, while I understand Also personally, |
@LikeLakers2 I agree with you, but it's not only about node path. I use Typing an I'm aware my ideal need cannot be implemented currently without corner cases though, mostly due to the impossibility to reset references to a node when it gets deleted in editor AFAIK (my current boilerplate has this issue anyways), though Unity is fine with it. Btw I'm not settled on the syntax, I mostly want the feature so I dont have to write all this code^^ |
@Zylann Ah. Well my concern about issues down the line with |
BTW, I haven't seen this syntax mentioned anywhere, so maybe people is not aware of it: export(NodePath) onready var node = get_node(node) Not sure if it may cause problems with serialization. |
@neikeq Oh nice, didn't think of that. If you could just supply a second parameter to the export for the type of node then, as @LikeLakers2 suggested, then that would pretty much deal with the initialization issue. @Zylann As for handling subsequent assignment type checking, I don't think that would be something you can support out of the box until Godot starts implementing optional static typing in GDScript. You'd have to actually create an Object that you assign values to and which performs the type checking for you (like the Wouldn't you then have to make modifications to Variant, telling it, "Hey, you, this instance, you're gonna only be null or Object instances deriving <class>." Then GDScript's export would be able to setup that property. |
@willnationsdev as I said, the feature I expect is doable in current Godot, just can't cover all corner cases, and syntax is a formality. I guess I'll stay with all my boilerplate for now... :/ |
@blurymind since you are wondering about it, this could be illustrated as...
You might then see a "Sprite" property in the Inspector and could assign only a Sprite or Sprite-derived node to that value. Now, whether it shows up in the Inspector as a NodePath or something else, I don't know. Would probably need to be a NodePath since nodes don't have a design-time ID of any sort. But then, if the value displayed in the Inspector were a NodePath from the current node to the node represented by the stored NodeRef, you could update the NodePath's value anytime the targeted node was reparented, via a signal. |
@willnationsdev node paths would be used only for serialization purpose, in any other cases the property would behave like a normal pointer to the node, in terms of usage (so no node path in the inspector). Which means there is no update to do when the node is moved in the tree, it just works (tm). But I think other details were discussed earlier in this thread. |
@LikeLakers2 One nice way to express that in C# would be |
this would be so nice for error checking. |
I'm not familiar with GD script as I have just been using the C# interface, so I may be missing something in this conversation. However I think it is extremely important that Godot have a good way of assigning a node reference to a variable in a script. Currently the only way I am aware of is using an exported NodePath. This works fine except that if node A has a script with a NodePath that points to node B, the NodePath will not be updated if you move either A or B in the same scene. This is NOT good behavior under any interpretation! If the nodes are in the same scene, the editor should update all the affected NodePath values in order to preserve references within that scene. This is certainly how other engines like Unity work and is critical for efficient workflow. Why on earth would you NOT want to update the NodePaths? Otherwise a NodePath is little better than a hard-coded path and is nearly as rigid. I dread any time I have to rearrange nodes in a scene at this point because it breaks all references and I have to re-assign all the NodePaths in the editor. I am not asking for this to happen at run-time, only in the Editor, and only within a single scene. Just update the NodePath values. It is possible to over-complicate anything, but we just need a simple way to easily assign nodes to variables in the editor. |
@BrianCook This is being tracked in #3163. |
In fact I believe Unity does not even need to do that, because it stores game object "fileIDs" (i.e the ID of an object within the scene file), not their path. Which works fine as references by design.
I thought Godot was already updating NodePaths 🤔 |
@Zylann Afaik, Godot does update exported NodePaths automatically if the referenced node's relative path from the current node is changed. What is not yet supported is automatically converting the value to a Node and enforcing type constraints on the exported NodePath target, e.g. for GDScript's optional static typing. |
It's a shame that feature wasn't implemented yet. That ruins all the workflow. Serialization is not an excuse because you can easily extract NodePath from NodeRef and vice versa. So far we just need a wrapper that holds node sessional id and handles like a real node inside the code. (Not to mention type restriction in editor.) |
Feature and improvement proposals for the Godot Engine are now being discussed and reviewed in a dedicated Godot Improvement Proposals (GIP) (godotengine/godot-proposals) issue tracker. The GIP tracker has a detailed issue template designed so that proposals include all the relevant information to start a productive discussion and help the community assess the validity of the proposal for the engine. The main (godotengine/godot) tracker is now solely dedicated to bug reports and Pull Requests, enabling contributors to have a better focus on bug fixing work. Therefore, we are now closing all older feature proposals on the main issue tracker. If you are interested in this feature proposal, please open a new proposal on the GIP tracker following the given issue template (after checking that it doesn't exist already). Be sure to reference this closed issue if it includes any relevant discussion (which you are also encouraged to summarize in the new proposal). Thanks in advance! |
Could we have a shortcut to assign Nodes in the inspector instead of only relying on NodePath?
Explanation:
I had to link individual nodes several times in my project, especially in tool scripts,
but I quickly found that I was repeating myself doing so.
Everytime, my code looked like this:
I have to:
That's a lot of boilerplate, just for ONE property.
It would be really cool if we could instead have this:
This would still be saved as a NodePath, however at deserialization, if the exported type inherits Node,
all of the previous boilerplate would be done to assign the field automatically.
As a bonus, because the node type is known, we can prevent designers from assigning wrong node types in the editor by greying them out in the selection window and cancelling drag and drop.
It won't break compatibility either because using NodePath would still work if needed.
What do you think?
The text was updated successfully, but these errors were encountered: