-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Access Scene Unique Nodes in code with a $$
operator/literal
#5064
Comments
This proposal has been a long time brewing in my head. I mustered some courage proposing this potentially highly controversial change thanks to the Godot community on Discord. This proposal depends on #5048's implementation, to be an even more justifiable addition. |
I'm personally for this change, I agree with |
I also don't like how overused % is and how many different proper syntaxes there are for scene-unique nodes. Though the more I think of it, the more I approve of it. I'm still in support of adding
But the highlighting idea...
|
strongly for both four ways to do the same thing is a mess.
some contributors in the other proposal were saying that this has already been discussed and we are too late for this, but most of this has actually been proposed early on in the PR and got a decent amount of approval, so what are we supposed to do... the notion that we should wait for strong community backlash before changing it is strange too. of course there's not going to be strong feedback from many users, after all it's not like the feature is unusable. but that's no reason not to clean it up before stable. btw, in the last line of your screenshot example, lastly a mention on the side, if the popular #1776 were to be implemented, chaining like that would become possble: |
Five, there is also
|
Indeed. I was afraid of mentioning this proposal, to avoid going too off-topic, but to me personally, that syntax does look much less headache-inducing than the current sequences of **%**s.
Time to add it to the pile... |
Note that this proposal conflicts with #996 and I find $ for normal and $$ for caching more intuitive than $ for normal, $$ for unique and... what? for caching... |
Scene Unique Nodes are inherently cached, so in a way, that very proposal would be implemented if this one is, but in a way that is more integrated in the Engine. I do not see any conflict. |
@Mickeon I don't want to have to use unique nodes to benefit from caching. And the obvious conflict is, you can't use $$ for both (non-unique) caching and unique nodes. |
If it's too much of an issue, storing Node references in variables is always a perfectly viable option, it's typically recommended and results in cleaner code, too. |
@Mickeon Unless you want the scene to have no script |
perhaps integrating caching as proposed by #996 into scene unique nodes is the only way we realistically get it at all, judging by the critique brought forth by groud, vnen, and Zylann in that proposal. btw, although reduz mentions "Implementation is very optimal, as these nodes are cached." in the unique scene PR, this is not the caching proposed by #996, as performance of |
well I was thinking here, maybe remove the "%" since its used for strings like: # $_ get node
var s = $_myNode
# $U_ get unique node
var s = $U_myNode
# $C_ cache node
var s = $C_myNode |
This convention would heavily go against the first point brought up in the proposal. |
I'm not a fan of |
Idea. I would like to say that @ is not used anywhere in gdscript, and that it makes sense here "at". However after just checking, the above example of ^ to indicate a nodepath is apparently wrong and it is in fact @ . From the docs: But my point stands. Use a unique symbol that isn't used elsewhere in the language. And merge it with the get_node $ call. And don't support unique names in get_node because it's pointless. |
It's used for annotations. It was NodePath in 3.x, but in 4.0 NodePaths are |
Yeah, sorry. As much sense as that makes, "@" has been taken. Because of their rather unique purpose, either the annotation's symbol is changed to make space for that suggestion, or this is still up to debate.
As of currently, it seems like the support is not just within
|
Also, bit funny how this goes: In the proposal I confidently called It's a really small mistake, it's true, but it may partially be attributed to how "littered" this current syntax feels. |
make sure to check the latest docs. just swap "stable" for "latest" in the URL.
sure, but easier said than done. the currently chosen
not sure what you mean exactly, can you give an example? |
I did give a example. Use $ or get_node() to try and get a node by it's Path. (This path my be cast from a string.) Use @, which is now actually free to use then (excepts it's used in export notation), or another symbol to reference a unique node. Make it § for all I care. Again:
|
which is probably enough to exclude even
looks like you are sitting on a German keyboard, too. |
No... it's present on the british and us international standard layout. In fact, we could just as well use ° which is also present on both. It doesn't matter. My feedback is much less so about the symbol. But about it's function. Outside of a string path. Not inside. |
You guys should've just changed how
|
Accordingly, even if we replace the Personally, I don't see the need to replace |
Hm, @ does indeed make a lot of sense. I guess using it for annotations is a resemblance to Python, but we could really have it do double duty when the uses are so clearly different (a node path does NOT look like an annotation) |
Just my two cents, potential operator changes that I wouldn't mind are ! and &. Personally, I lean more towards &. I do only prefer this under the circumstance that it would be used as a standalone operator and not in conjunction with $, though I'm not actually a big fan of that idea since it could lead to confusion for new users of GDScript. I only wish that as & $ have similar appearances in regard to size and height and whatnot. If we always use $ to indicate node referencing, then I would opt for !. This could be slightly confusing though as someone may be under the impression that it means "not", but the logicality behind it doesn't make much sense so I reckon it wouldn't be a huge deal. If not that, then maybe an alternative such as a '? Or perhaps ^? (Although I believe someone mentioned that ^ is used for instanced nodepaths in Godot 4, so maybe not a good idea) Whatever the case, we have to consider that whatever we make the character be, people won't be able to start their nodes' names with it. This shouldn't be a problem as the official style guide limits node names to not allowing for such things, but I say should be as obviously, not everyone reads it or fully follows it. |
|
Used for Also, Please note that release 3.5 has taken place, and now changing the scene unique nodes character is a violation of backward compatibility, which should be strongly justified. |
Please note that this isn't what the proposal is about. Whether or not % can stay in NodePaths as is is obviously relevant in the discussion, as they tackle the same thing, but both can technically coexist without nearly as much compatibility break as first though:
Indeed. However, as a community approving of this feature, it is fair to say that we want to make it right before it seriously is too late. Unfortunately 3.5 officially came out around the time Godot 4 hit feature freeze, and not enough people have tried Scene Unique Nodes to give enough opinions before this time. |
I honestly would prefer if this just, did not work. Looking up nested scenes children wasn't something users were doing often in the past. Because it was finnicky and unreliable. And is something we shouldn't give them the tools to accomplish either. The problem with @Mickeon To clarify, you keep talking about
The feature was developed and merged with over a hundred posts in its proposal, with many questions left outstanding rather than answered in my opinion. It is a good feature, but the work wasn't put in to account for how it will interact with the rest of the engine and workflow. (It's hard to predict such things, so it's not like we could have known. And it was proposed for 4.0, not 3.x.) This was a case of overeager backporting. So, honestly, screw a little bit of backwards compatibility if we can make it so much nicer to work with. Funfact: The original proposal used @ |
I agree that there are rational ideas in this proposal, and it would probably be better to go this way initially. But it seems to me that the problems described in the OP are exaggerated in order to change something. It is unlikely that someone will use all these different ways, most will prefer the shortest option. There are many ways to access nodes, even without considering unique ones:
But this is not a problem. As well as combining unique nodes with a format operator. This case is too rare to worry about. But I want to emphasize: I'm NOT strictly against this proposal, I'm just confused if this issue is worth such attention. But given that this is a very young feature, I think the maintainers here should be able to predict the remaining lifetime of the 3.x branch and how quickly the main user base will switch to 4.x. Perhaps breaking compatibility here is worth it. |
this proposal as well as #5048 both hint at the removal of the unique node accessor from node paths. I'd move this more into the foreground of this discussion as I find that's when these proposals begin to really make sense. the arguments I made were assuming a good bit of the critique in this thread boils down to the suggested changes not being reconcilable with the accessor as part of node paths. that critique would no longer be relevant. why remove Mickeon explained:
and TheDuriel, too:
now with no longer having to consider the accessor as part of node paths, look at this again:
no alternatives. to be clear, as long as the |
Agreed! Now replace
@ is sadly somewhat unavailable despite its very fitting meaning, thanks to its new use in exports. But that still leaves others commonly found symbols available. |
not just in the future, additional annotations may be added that are not just used in class declaration but also in function scope (
ok but again, easier said that done.
since personally my favourite remains the awkward % icon in the editor GUI would then be replaced with an asterisk like star icon - fittingly as an unique node is a kind of favorite node, and the star is commonly associated with favorites. |
Edit one year later: The last one might actually work as it's a binary operator. |
ah, wasn't aware, that's out too then
yea but that's fine, the bitwise operators are pretty much available in this context (as a prefix to a string). which is not to say that I advocate for those, just confirms my point that it's really not trivial if possible at all to find a single character other than |
On my keyboard I do not have easy access to |
This is just not true. Accessing scene unique nodes has a similar speed to accessing non-scene-unique nodes. There is a noticeable performance penalty when getting nodes, less than a microsecond for each, but it adds up. Here are some test projects to benchmark this, for both Godot 3.5-stable and Godot 4.0-alpha14: |
This comment was marked as off-topic.
This comment was marked as off-topic.
@BaddRadish I heavily suggest making a new Proposal or a Discussion for this, because your suggestions prove difficult to discuss in a comment section that should specifically be about this current Proposal. |
i disagree that this is not "about this current Proposal". i only talked about things other people talked about in the comments. the conversation is going in circles because people aren't addressing the syntax as a whole. "we cant do logical thing A because arbitrary thing B already exists". need to play musical chairs to fix the problem or /none/ of the above suggestions will work. |
@BaddRadish What Micky was saying is that discussion of a particular proposal should focus on the pros and cons of the provided solution, as well as adding polish to the proposed implementation where needed. Whereas "I have a radical idea that would also fix the underlying issue" deserves its own proposal, which you can then link here. |
The GDScript team talked about this proposal during a meeting. We think that the proposal was a good idea when it was written (August 2022, before the 4.0 release), but now, it's not something that we think is a good idea for now, as % sign is widely used right now. Thanks @Mickeon for the proposal though! |
Describe the project you are working on
A Typical 2D Godot game, dipping my toes with Scene Unique Nodes.
Describe the problem or limitation you are having in your project
Scene Unique Nodes are a positively received feature, but I do personally find the way this feature is accessed in via code to be potentially troubling in the long run, and it all has to do with the implementation of "%":
get_node("%Node")
feels... unrefined, to say the least. Even with mastery of the language, the use of a character to symbolise this interesting way of accessing Nodes feels inherently unpolished, seemingly going against the simplicity to read code, and ease of access that Godot strives for.Very much granted, this is a highly unrealistic example, but it showcases how overloaded the operator is.
get_node("%Node")
is valid syntax, and so are$%Node
,%Node
, and$"%Node"
. I personally believed GDScript was designed to write code that's easy to look at, but with many variations of the same operation, as well as the usage of a very arbitrary character to symbolise it, this goal is quite potentially hindered.get_node()
. This is unlike the "$" literal, that has been commonly utilised in every tutorial, has been simply summarised as a shorthand, but most importantly, servers one, and one specific purpose only, across the language.Describe the feature / enhancement and how it helps to overcome the problem or limitation
Implement a "$$" operator/literal. As "$" is considered to be a shorthand for
get_node()
, it would intuitively make sense for "$$" to be a shorthand for a theoreticalget_unique_node()
#5048. It fits like a glove. Still accessing Nodes, but in a way that's different and special enough to warrant its own operator that is easy to tell apart and is just logical, instinctive to type.This operator would obviously be summarised in the GDScript Basics, like "$" already is.
GDScript is no stranger anymore to double-character operators. In fact, recently, the exponentiation operator has been merged. Despite
pow()
already existing, its inclusion feels somewhat natural, simple. If "*" symbolises multiplication, it fittingly makes sense "**" is a stronger, albeit more specific variation of a multiplication.This proposal also heavily suggests to outright remove the "%" as a Scene Unique Node accessor. It doesn't seem mandatory, as both could coexist, despite the spoiling of choice it would cause. By removing it, long, mixed NodePaths such as
^"%UniqueNode/DirectChild/%UniqueNode/AnotherChild"
would no longer be possible, and other languages may especially struggle fetching highly-nested Nodes.Although, it's really worth debating the usefulness of this somewhere else.
To conclude, this inclusion may warrant a change of Scene Unique icon on the SceneTree, if it's still being utilised.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
If this enhancement will not be used often, can it be worked around with a few lines of script?
It cannot.
Is there a reason why this should be core and not an add-on in the asset library?
The entire topic is core and cannot be modified with add-ons.
The text was updated successfully, but these errors were encountered: