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

Scene unique nodes should be globally accessible #5133

Closed
elvisish opened this issue Aug 10, 2022 · 7 comments
Closed

Scene unique nodes should be globally accessible #5133

elvisish opened this issue Aug 10, 2022 · 7 comments

Comments

@elvisish
Copy link

Describe the project you are working on

3D first-person action game.

Describe the problem or limitation you are having in your project

I'm trying to access scene unique nodes from a separate scene and they don't work as expected. When trying this code:

func update_ui(which):
            $"%item".show()
            $"%item_count".text = str(item_count)

It gives me an error:
image

But forcing it to check on the parent scene that contains it, does work:

onready var UI = get_tree().get_nodes_in_group("ui")[0]

func update_ui(which):
            UI.get_node("%item").show()
            UI.get_node("%item_count").text = str(item_count)

Describe the feature / enhancement and how it helps to overcome the problem or limitation

It would allow scene unique nodes to be simpler to use when they're not inside the same scene as they're called from (most UI's will be in a different scene from the script that keep track of the amount items held in a game).

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Just allow the node to be accessed as usual without needing a parent reference for unique scene nodes in separate scenes from where they're called from.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No, needs to be a GDScript adjustment.

Is there a reason why this should be core and not an add-on in the asset library?

No, needs to be a GDScript adjustment.

@Mickeon
Copy link

Mickeon commented Aug 10, 2022

Indeed, Scene Unique Nodes' implementation does not account the cases where scenes are nested in one another, but the solution proposed here can prove more problematic in the long run.

See also: #4601

@elvisish
Copy link
Author

Indeed, Scene Unique Nodes' implementation does not account the cases where scenes are nested in one another, but the solution proposed here can prove more problematic in the long run.

See also: #4601

Does referencing the parent scene in my example still cache the unique node? Cause if so, they're still useful in separate scenes.

@YuriSizov
Copy link
Contributor

YuriSizov commented Aug 10, 2022

Well, they are called scene unique for a reason. This is a scene-based mechanism, and to have global unique nodes it cannot be used as is. With the introduction of the get_unique_node() (#5048) method the syntax for accessing them from other scenes won't even be that confusing, though.

No, needs to be a GDScript adjustment.

This doesn't seem to be a fair answer to the question about possible workarounds. You have demonstrated a workaround. And to scale it globally you can have an autoload singleton with node references too.

Just allow the node to be accessed as usual without needing a parent reference for unique scene nodes in separate scenes from where they're called from.

Unfortunately, this is not sufficient for a technical proposal. Please refer to the aforementioned discussion (#4601) or start a new one.

@YuriSizov YuriSizov closed this as not planned Won't fix, can't repro, duplicate, stale Aug 10, 2022
@elvisish
Copy link
Author

elvisish commented Aug 10, 2022

Just allow the node to be accessed as usual without needing a parent reference for unique scene nodes in separate scenes from where they're called from.

Unfortunately, this is not sufficient for a technical proposal. Please refer to the aforementioned discussion (#4601) or start a new one.

Okay, but can you answer if accessing them from a parent node is still cached or not? If so, it's not much of a problem as it'll still allow for a single reference without a huge path chain, and it won't be as slow as finding a node by name.

@Zireael07
Copy link

That's a headscratcher. Whatever ends up done, this limitation needs to be better documented...

@elvisish
Copy link
Author

That's a headscratcher. Whatever ends up done, this limitation needs to be better documented...

I have to watch this video just to remember how to write the unique node syntax: https://www.youtube.com/watch?v=HKaPTdZKG8Y

@Mickeon
Copy link

Mickeon commented Aug 10, 2022

Okay, but can you answer if accessing them from a parent node is still cached or not?

Currently, get_node("%Node") is a bit faster than get_node("$Node"), because get_node() doesn't have to travel through the tree nearly as much, but it's not any faster than storing the Node in a variable to use later (var node := get_node("%Node"), node.queue_free())

I have to watch this video just to remember how to write the unique node syntax

Thank you for being the "case" of the point these proposals have predicted was going to happen: #5048 , #5064 (❤️)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants