Faster & Better Access to your GODOT Nodes!
Вставка
- Опубліковано 1 лют 2024
- ▶︎ GODOT 4 COURSES : school.gdquest.com/godot-4-ea...
🎓 FREE APP "Learn GDScript From Zero" : www.gdquest.com
🎮 FREE INTERACTIVE GODOT TOUR - The Godot Editor - www.gdquest.com/tutorial/godo...
🗨 *DISCORD INVITE*: / discord
------------------------------------------
🖋 SYNOPSIS
This video shows you how to access Godot's nodes in the editor more efficiently using unique names and node caching.
#gamedev #gamengine #godot
-------------------------------------------
CC-BY 4.0 LICENSE --- Assets & Videos
creativecommons.org/licenses/...
Attribute To: "CC-By 4.0 - GDQuest and contributors - www.gdquest.com/"
MIT --- Code
opensource.org/license/mit/
"Copyright 2024 - GDQUEST.COM"
i love this channel graphic design, is beautiful.
Yeah, it's like "Kurz gesagt - In a Nutshell", but for Godot :)
I really dig it too! I wonder if this particular style has a name..?
it's because of clear explanations like these that i've decided to subscribe to your 2d and node course, thank you
Wow, thank you so much, man. I've been trying to play with values in different scripts for so long now. This is INSANELY easier than anything I've made work thus far.
wow i worked 4months on a game demo and just released it yesterday. i never knew it existed, my top block is FILLED with onreadys.
The takeaway i have from this video is that in almost all cases (if you arent dependent on an external editor) you can always use Unique names and save yourself some code lines (and performance)
Pretty much plus it kind of doubles as documentation. You can quickly scan a scene and see which nodes are used in code for sure. Then if you make sure all nodes you use in your code have unique names, it's even more useful to quickly spot the others.
Love ur chanel man! Ima unity refuge who learning godot but I have only begginer courses and not very up to date,
Your endless stream of awesome content helps me ALOT to really sink in with this new engine ❤
I didn't know you could do this XD Thanks GDQuest!!
dude. been using godot for a good month or two now - i had no idea this feature even existed. this is brilliant, thanks a ton! also just now learned you can actually drag nodes into the script editor XD duh!
Awesone video as always!
OMG this is so incredibly useful, thank you!!
Awesome! I had no clue about this feature.
I’ve been following the GDQuest Learn 2D from zero and it’s been very good. Thank you Nathan and GDquest for your contribution to the Godot community!
Thanks for your feedback! It's very nice to read :))
Soo good glad I watched this one, it just got rid of my biggest annoyance
Nice work 😂😊
Nice! I'm curious how much of a performance increase is it from using regular onready vars?
Yup, me too. I'm using mostly the $"nodename" syntax and curious if I should bother switching to %"nodename"
@@julienb5815If it tells it to aggressively cache those references, I can imagine it is quite fast.
It doesn't make a performance difference with onready variables. It mostly makes a difference with using the $ or generally getting node with nude paths, because instead of reading the path and finding the nodes each time, the reference is cached for you.
@@Gdquest Ah good to know. So since I mostly use $ with onready (for typing, too, like you do at 3:05 with %), then no difference 👀 Thanks
@@Gdquest you said nude paths...
Might wanna fix that before UA-cam decides to censor that.
This sounds very handy - is this also usable with C#?
I pre-ordered all the courses. Looking forward to become a Godot Master
😊😊 Hope you enjoy the first modules we released a few days ago for the 2D course. More on the way!
@@Gdquest it's so well written! Enjoying it a lot
I would love to support and learn from your course, but unfortunelly in my country this course is almost as much as a minimum wage. But I love your videos, I learn so much with them, keep up the good work :)
I completely understand that's why we offer regional pricing. We're still implementing it on our new site but if you like, you can email us at support@gdquest.com and we'll send you a coupon that adjusts the price to your country so you don't have to spend a month's wages on the course.
is it better than using a singleton pattern? like for game managers? also i hope an extension for visual studio or visual studio code is made so the last part in the video will not be necessary anymore
This is cool ❤as always,
🤔
but can it really save performance
I mean I still have to make on ready variabls can it really make the performance better?
I love to know
2:11 at part
%PlasmaGun.shoot()
Is that a custom function call from plasma gun node?
Like in plasma gun script it has func _shoot() ?
We can reference it like that? Or that's only certain syntax like .play()/.show()/.hide() ?
Here's a pattern I started using in Unity a few years back I call the "deferred caching getter" (useful when you can't or don't want to use `@onready`):
```
var thing: Type:
get:
if not is_instance_valid(thing):
thing = get_tree().current_scene.get_node_or_null(^"Thing")
return thing
```
This is really useful for accessing scene-relative objects that don't have a specific relationship to your script (eg: the player) or have an inconsistent lifetime (eg: fired projectiles, sound emitters, or particle effects)
Now if only GDScript had better metaprogramming, you could encapsulate that in something like @cached_property
What happens when you rename the node? Will it rename the references in the script?
I don't like how it relies on a string (the name of the node), which can be changed by anyone working in the project.
Export tag and dragging the node in the inspector seems a much better solution than this.
For anyone who works on the engine, is there a performance increase (better caching or something?) over just making variable references?
Such as:
--------
var camera : Camera3D = null
func _ready():
camera = $Camera3D
--------
Or is this just a more convenient way of doing the same thing?
(I know I can use onready, but I am not a huge fan of using that)
It doesn't make much of a difference with creating onready variables and storing the reference there. It mostly makes a big difference for people who constantly get the nodes using the $ notation and node paths. And if you prefer, it can remove the need for onready variables.
@@Gdquest sweet, thank you. I was making sure I had it right in my head.
What about using an export tag and dropping nodes in? Wouldn’t this be more modular?
An advantage of this is that it can work across scenes right? For example my player scene will be able to access my %World scene directly right?
Unfortutantely no :/
@@tomaszgoral8154 dawww!
Why not just use @export var? Hardcoded references just don't seem like a good idea since you could change the name, change location, or remove it altogether. In Godot 4.2, if you drag the reference in the editor to an exported variable, then the reference automatically updates if you make changes to it in the editor. It's better than adding a file path since the path changes automatically in reference, and you only need to drag it in. It's better than the modulus unique name reference because you don't need a unique name either. What's the tradeoffs?
I was excited until you mentioned the typing downside :(
Still good to know, didn't know this was added, good stuff.
Is there a way to check for a cached node? In other words, if I have a node, and I want to check if it exists or not, but I don't always know in the scene where it will be, so I can't use "has_node"?
There is "find_node" but I would recommend reviewing your architecture so you don't have to use it.
does the % naming use static typing? your lines are marked as unsafe in the editor
I should watch a whole video before I comment lol
How does this work with scene instances? Will having multiple instances of the same scene cause any conflicts?
Not that I've seen so far
it's local to the scene
The % UniqueName is stored to the Owner node of the Scene (the instance of the PackedScene). As a C++ hashmap (think GDScript dictionary). When you get_node $ , one of the first checks done is for the % token. Which will then check the Node's Owner for a match in that hashmap. And return the Node reference stored there. Duplicate instances will use the hashmap in that particular Owner. So there's no conflict.
Just a note... in 4.2, the typing is not working when using nodes referenced with $ as well, even if the scene is open and active.
Thanks for pointing this out! I hadn't paid attention to this. I hope they bring it back.
I'm using Godot 3.5 but it shows a tokenizer error how to fix this?
Hello! Bientôt les version G4 des courses? :D
Hello back! Oui ! Nous avons déjà commencé à publier les modules de Learn 2D Gamedev.
Am I the only one having problems getting code completion to work when using unique names? I notice that GDQuest is getting code completion for .current on his camera, I only get the stuff from Node. Currently running v4.2.1, but same issue in earlier v4 versions. Is there a setting or something I need?
works fine for me. you using a % or $ symbol?
Just "%Camera2D." and after typing the period the code completion pops up but only contains stuff from Node.@@ince55ant
Nice. Unfortunately, it's not available in C#
This works with c#?
What about those students (like me) who can't afford to buy your courses, but are genuinely interested in Godot Game dev Professionally?
We also offer student discounts. Just send me an email to support@gdquest.com using your school email account and let me know what courses you're interested in.
Alternatively, talk to your school/uni and see if they're interested in using the course. We have a program for schools that is really accessible for public institutions and that includes the whole learning pathway.
Bro can you make a tutorial godot in mobile please
I use the @onready. Since if you select them and drag them to the editor while pressing CTRL they get automatically added as @onready
What's the difference between this and onready var node = $myNode?
Edit nvm it's in the video lolol