Use this space for questions related to what you're learning. For any other type of support (website, learning platform, payments, etc...) please get in touch using the contact form.
How to determine the root node for a new sceneQholmes98One thing I’m not quite grasping yet is how to determine the best node to use as the root for a new scene. For example, you use area2d for the health pack, if I understand this correctly it’s simply because the main job of this entity will be to detect when something enters it. However, would it work the same if we just use generic Node2D or a Sprite2D and attach an area2D as the child? I may be overthinking it but whenever I am working on something that isn’t guided I often struggle to pick which node, especially on more complex scenes.510Feb. 21, 2024
The leading _ on some names?ragsdrI forgot why this was and had to look it up.
In case anyone has this question, this is what I found:
"This is a common convention in many programming languages to denote methods that are not part of the public API of a class and should not be called from outside the class."
Thanks, MS Copilot!17Apr. 09, 2024
How does a collision node make an area node "know" its being hit?GurkI find difficult to understand (Just have to accept it for now) why the area node has an "area entered" signal but until you give it a collision node child it does not fire.
Yes, I see that the collision node gives the shape of the collision area, but the parent node just searches for any collision shapes in its tree to know which shapes should fire the signal? I didn't tell the area node which collision node to check for (The same way we add a shape value to the collision node). If so, I guess there will be other nodes that have that synergy between them, isn't it?56Feb. 21, 2024
Signal with Code = No Signal Icon 🛜snowm8nConnecting a **signal** through the **node** **panel**, it was showing a little 🛜 icon. Now that we are using **code**, should that 🛜 icon appear? If so, where should it appear? Or is it normal to **not** get the 🛜 icon because its being setup through code?13May. 25, 2024
Can you use multiple collision shapes for one node?FioretinSay for example the node has a complex shape (like a tree, or a person, or an abstract shape). Is it possible to use multiple CollisionShape2D nodes to check if something enter the shape, or will that cause some sort of error?42Aug. 30, 2024
Best place to put scripts?slim-lemurHaving read through a couple QnA's here (Nice feature by the way, it's like if every "after class, 1 on 1, follow-up" discussion was documented) I understand that developers can rest easy when deciding what node should be the root of their scene. They can pick a generic node2D and, if need be, refactor it to something more specific later. (As required by your game)
But what about scripts? Where is the best place to put them? Given how you access nodes, and how functions like "queue_free()" behave, it seems like putting the script at the "rootest" node it can be has a lot of benefits. But what's stopping a dev from putting everything in a giant script in the root node of a scene? In other words, what would be the benefit of making scripts in children/lower-in-the-hierarchy nodes?
P.S. is it "node tree" or "scene tree"?32May. 26, 2024
Type hints enabled, but no longer working.leafI am just getting started in this module, and have found that something may not be working as it was in the previous workbook.
When typing this code with type hints enabled:
`func _on_area_entered(area_the_entered: Area2D) -> void:`
`pass`
Isn't the `-> void` part supposed to come in automatically? I went back to the previous module and reviewed the beginning where 'type hints' was suggested and how to enable it, my settings seem to be fine. I just want to learn more about this, and why it's not working as intended.
The `-> void` part isn't required correct? Also, if I were to manually type `-> void` after the parameter section, is it still the exact same characters that Godot would automatically fill in?
And one last thing about threads/forum posting:
```gdscript
I have noticed when I insert a code block:
pressing enter 3x does not exit the code block
How do I exit these fields so I can continue typing normally?
what am I doing wrong?
```32Apr. 20, 2024
How to determine node hiearchy?GilbertTheGreatHi! Was wondering why we set the Sprite2D note as a child of Area2D for the health pack, rather than setting the Area2D (with it's accomanying CollisionShape2D) as a child of Sprite2D? To me it feels like Sprite2D is the "main" node, though I can't really explain why.12Mar. 09, 2024
Can I define my own nodes?rowdy-rhinocerosIs it possible to define my own node templates (and add them to the standard nodes), where I can define my own signals to emit? etc... If so can can you give me a reference where to read about it in the documentation, thx11Aug. 25, 2024
Thank you.Dr. BuniI have tried to learn Godot several times the past few years, and I never got far. Sure, some knowledge stuck, but some concepts were so confusing to me, frustration would slowly eat up my desire to learn coding (so I would always run back to RPG Maker).
But today, for the first time, I understood how signals function. There's a lot of different things going on when you have to connect a signal by code, and no matter how many tutorials and reddit posts and discord messages I read, it never made sense to me.
But explaining it with ELI5 terminology such as delete_the_health_pack and what_touched_the_health_pack helped SO much. So, thank you!11Jul. 08, 2024
No indication that CircleShape2D can be expanded to show additional properties berkeleynerdI find the lack of any kind of arrow indicating that the `CircleShape2D` resource in the *Inspector* can expand to display its properties unintuitive. An option in the editor settings to automatically expand these would be a nice feature to add as well.21Apr. 20, 2024
HELP~dofudengameshow to play the animation using code this is just something that i am making, it's an add-on40Oct. 29, 2024
Can I create my own signals?PurpleSunriseSo far we used node's default signals that do specific things (timeout, area_entered).
I was wondering what if I want to create my own signal? Can I definite it from scratch?
Just making this one up, maybe there is a signal already for this but, let's say I have let's say that I have a Sprite2D node and I want to send a signal when its scale changed. Could i just go:
```gdscript
_ready():
sprite_scale_changed.connect(_on_sprite_scale_changed)
func _on_sprite_scale_changed(scaled_sprite : Sprite2D):
#something happens
```
Something like this? It's just a curiosity that came up to my mind now, maybe it will be answered later on this course.
Thank you!10Oct. 12, 2024
Typo health path?PurpleSunrise> The node that entered the area. When the `Area2D` node emits the `area_entered` signal, Godot will pass the node that touched the **health path** as an argument to the function. This is a predefined behavior of the `area_entered` signal.
Did you mean health pack?
Thank you!10Oct. 11, 2024
I try to use Gems to increase my speed but...Mazi```gdscript
extends Area2D
var health := 10
var gem_count := 0
@export var speed := 1200
@export var max_speed := speed
@export var boost_speed := 3600
@export var boost_on := true
var velocity := Vector2(0, 0)
var steering := 3.0
func _ready() -> void:
area_entered.connect(_on_area_entered)
set_health(health)
var timer := get_node("Timer")
timer.timeout.connect(_on_timer_timeout)
timer.one_shot = true
timer.wait_time = 0.5
var timer2 := get_node("Timer2")
timer2.timeout.connect(_on_timer2_timeout)
timer2.one_shot = true
timer2.wait_time = 5.0
func _process(delta: float) -> void:
var direction = Vector2(0, 0)
direction.x = Input.get_axis("move_left", "move_right")
direction.y = Input.get_axis("move_up", "move_down")
if direction.length() > 1:
direction = direction.normalized()
if Input.is_action_just_pressed("boost") and boost_on:
max_speed = boost_speed
$Timer.start()
boost_on = false
$Timer2.start()
var viewport_size := get_viewport_rect().size
position.x = wrapf(position.x, -50, viewport_size.x +50)
position.y = wrapf(position.y, -50, viewport_size.y +50)
var desired_velocity = direction * max_speed
var steering_vector = desired_velocity - velocity
velocity += steering * steering_vector * delta
position += velocity * delta
if velocity.length() > 0:
get_node("Visual").rotation = velocity.angle()
func _on_timer_timeout() -> void:
max_speed = speed
func _on_timer2_timeout() -> void:
boost_on = true
func set_health(new_health: int) -> void:
health = new_health
get_node("UI/HealthBar").value = health
if health > 100:
health = 100
elif health < 0:
health = 0
func set_gem_count(new_gem_count: int) -> void:
gem_count = new_gem_count
if gem_count < 0:
gem_count = 0
if gem_count >= 1:
max_speed = speed + 1800
elif gem_count < 1:
max_speed = speed
get_node("UI/Gem_Count").text = "x " + str(gem_count)
func _on_area_entered(_area_that_entered: Area2D) -> void:
if _area_that_entered.is_in_group("energy"):
set_health(health +10)
if _area_that_entered.is_in_group("gem"):
set_gem_count(gem_count +1)
if _area_that_entered.is_in_group("death"):
set_health(health -10)
set_gem_count(gem_count -1)
```
Hello!
The code above what I try to upgrade almost every day. Today I tried "if you have "Gems >= 1", your speed increase but if gems changed to zero your speed will change back to original".
Question 1: why I have to manipulate "max_speed" not just the "speed" variable while max_speed := speed? In the code you can see how I solved my problem but I don't understand the why. :) Thank you for any help!
Question 2: If I wanted to stay the gem_count zero and not going to negative I had to put the "If statements" before the UI change but when I did the same with health the position of if statements does not matter. It is because gem_count uses label text?40Aug. 26, 2024
Suggested note for "gotcha"jumpy-goatScrolling through the questions that are already posted for this lesson, thankfully it looks like this problem hasn't hit too many people who have taken the course before me. And for what it's worth, as I was paying attention to the code examples you were providing, I was easily able to avoid the mistake, however I expect someone out there might not be so lucky and then have a really frustrating time with this...
The code to connect a callable to a signal **must not include** the parentheses on the callable method. `area_entered.connect(_on_area_entered)` cannot be written as `area_entered.connect(_on_area_entered())`. For a new developer who's relying heavily on the script editor's autocomplete functionality, this can get them in trouble. I tested this while I went through the lesson and found that Godot would autocomplete with the parentheses as it recognizes the name as a callable function. I had to know to remove those characters, or else I'm sure I was in for a cryptic error message (as I'm sure `void` is not callable). So again, this "gotcha" is not going to trip up many folks that are following your code examples by hand, but more so by those who put complete faith in the code editor doing the right thing all the time.
I might suggest just a quick note to clarify that the parens should be left out, to help someone avoid having a really bad day with this excellent course.10Aug. 24, 2024
Script orderoliver_gzzHey there, does the order matter; is something going to be wrong if we write the script like this:
func _on_area_entered(area_that_entered: Area2D) -> void:
queue_free() #deletes the node and its children
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
area_entered.connect(_on_area_entered)10Aug. 22, 2024
Ball.tscn should auto open in practice.CodeFoxSince in the PopTheBall scene you can't just open it with the editor. And the popup text is tiny on a 4k monitor. Besides, I think opening a instanced scene from the scene tree in the editor wasn't even a topic yet. I feel this could throw off people.70Aug. 10, 2024
A bug in the practice pluginuntimely-dogfishThe first checkmark (The ball has a collision shape2D) is unchecked and the "has CircleShape 2D" likewise,
even though I used both and all requirements are done, while the game works as intended (ball gets deleted, when collision appears).
Just telling you, that you know and can fix it.70Aug. 03, 2024
About collisionshapeHazlarHello,
I am more advanced on the course but I ask the questions where the lesson was discussed.
How come `area2D` is described as an area when it only represents a point as a node without its friend colisionshape which is also a visual area certainly inanimate of detection property, because in the collective unconscious, it is accepted that one does not go without the other?
However the link in the code is not indicated.
That is to say that nothing says that when the ship enters the **CollisionShape** -> **activates Area2D** -> **executes the actions if a script is attached**. Or is it also because this link is made internally via`area_entered` which exploits the `colissionshape` in secret :) ?
Thank you very much10Jul. 12, 2024
Order of scene creation?high-level-eelIs there a reason why we have jumped to deleting the health pack as the first scene to code rather than make it spawn?
My natural inclination would be to follow "create -> do something -> destroy" or "Start -> middle -> end" to coding, so something like:
1. Create the healthpack (make it spawn)
2. Have healthpack interact with the ship (raise health)
3. Delete healthpack on ship interaction (delete node)
It appears we are starting with the end state and working our way back, is there a benefit to doing it this way?10Jul. 10, 2024
Tried to add a 4th ball for learning and ran into errorquirky-curlewI tried to add a 4th ball for learning but ran into the below error:
E 0:00:03:0257 instance_create: Script inherits from native type 'Area2D', so it can't be assigned to an object of type 'Node2D'.
<C++ Error> Method/function failed. Returning: nullptr
<C++ Source> modules/gdscript/gdscript.cpp:390 @ instance_create()
This persisted even after deleting my attempt and trying to get everything as it was before. Not sure what I did. 10Jun. 26, 2024
Names are horrible to understandChanclinkHello !
I just had a problem with the practice because I did not understand that
`area_entered` was mandatory in :
`area_entered.connect(_on_area_entered)`
I thought it was a name that you gave it like a variable so during the pratice I changed it because `area_entered`, `_on_area_entered` and `area_that_entered` were too much troublesome for me to understand.
just saying so that people does not get confused like me, and maybe you could add a color scheme or something when you refer to a thing like this (I don't know the name, is it a function of the object Area2D node ? or something else, I think I grasp what it is but I cant name it)
PS : sry for any mistake, I'm not fluent (yet I hope)50Jun. 03, 2024
Mislabeled Lesson namenice-sheepHi, I just noticed that the pop the ball lesson is labelled as L2. P110May. 17, 2024
Some of the stars have box outlinesnice-sheepHi, right after opening the project, I attached a camera2D node to follow the ship. I then went towards the top left. A little bit afterwards, I started seeing faint grey box outlines around some of the stars.10May. 17, 2024
My Test says it has no circle collision shape even though it poped the Ballsalarmed-crocodilemy test says it has no colision shape for no reason at all40May. 09, 2024
Godot Crashing Macvirtual-louseCan't figure out what's wrong. Ever since I tried adding the main thruster scene or importing M5 workbook, Godot crashes. At first I had an error about blender enabled and no path, so I configured that path and also downloaded the FBX and set the path but it still crashes. Not I can't proceed with the course.10May. 02, 2024
My Practise's won't show up. alarmed-crocodileI turned on the checkbox but the Practise's won't show up10Apr. 30, 2024
A question regarding instances of the ball in L2.P1woeful-llamaI noticed that if you hover over the Area2D nodes "Ball", "Ball2", and "Ball3" with the mouse cursor, their description states that all of them are instances of the ball.tscn located in the "practice_solutions" folder. At least from what I can see. So, now I have a question.
The interactive lesson requires us to add a CollisionShape2D node to the ball.tscn file located in the "L2.P1.pop_the_ball" folder because it's absent in that specific scene. But how does this change affect the "PopTheBall" scene if it doesn't actually contain a single instance of the specific ball.tscn variation from the "L2.P1.pop_the_ball" folder that was changed by us in the course of the lesson? Am I misunderstanding something?
10Apr. 10, 2024
L2.P1 PopTheBall root node and scene confusionragsdrIn the L2.P1 practice, the instructions suggest that the PopTheBall root node is an Area2D, but for me it's just a Node2D.
Is there something I don't get about the practice or is this unintentional?
Thanks for the help! Great course so far.20Apr. 09, 2024
Ordering code?haunting-camelHi, gradually making my way through this course and feel like I'm getting the hang of it except for arrays, dictionaries and now this (presume all will improve with practice).
I just wanted to check something though - the first step here is to write the _on_area_entered function, that will later queue_free(), and then we're told the _ready() function. However in the next step/final code it's the other way around, ready() comes first and then _on_area_entered.
Is this a requirement for the code to run properly, or is it a personal preference of how to make re-reading code easier and the computer doesn't care?
I know that as a lesson we need to know how to create the signal before trying to connect it, but it threw me for a while of going back over the same segment several times before I gave up and had a peek at the final code to find out what you were expecting.
That said, thanks again for making this series, things are starting to stick and having ideas of what's likely to be the next step, having a stab at it before continuing and seeing how far off base I was. 10Apr. 06, 2024
Enjoying the course!each-toadThough i encountered a weird bug, where the L2.P1 would accept the CollisionShape2D, i entered the "Ball" scene, to add the CollisionShape2D, and it just kept telling me it didnt have the collision and they shouldn't be set per instance of the ball.. But then i added collision shapes to both the ball scene, and each instance of the ball in PopTheBall scene, and it worked! Weird.. Ill reset it and give it another go, and see if it changes results :D
Either way, really great course so far!10Apr. 01, 2024
Connecting using code but between different nodessturdy-mongooseAs far as I understand, in the example here, we connect a signal `area_entered` to a function `_on_area_entered` and both live in the same node "Area2D". So we just have to write `area_entered.connect(_on_area_entered)` inside the script of that node.
How would it work to connect using code but between different nodes. I see several cases :
- a parent sends a signal to one of its child
- a child sends the signal to one of its parent (direct parent or grand-parent etc.)
- a node sends a signal to another unrelated node (or at least their are distant cousins in the same scene maybe)
I have the feeling that doing such connexions was feasible in the Node dock since you could navigate to any node, but I wonder how to do it using code.20Mar. 29, 2024
My list of Properties of CollisionShape2D node differsAleksMy list of Properties of CollisionShape2D node in the Inspector tab differs from what's on your picture: I can't see "Radius" property, I see "Disabled" property right under "Shape" dropdown list. Probably, some IDE settings are different, but I can't figure out where. My version is the same: 4.2.1.stable20Mar. 24, 2024
I may be stupidFernandoUnfortunately I can not explain what I did not understand since I did not understood anything.
It is in these moments I really wished for to diagram explaining what does what, what connects to what in what why, and why it is the way it is.
This might be a good idea of what I am saying: [https://snipboard.io/m2AYQK.jpg](https://snipboard.io/m2AYQK.jpg)170Mar. 24, 2024
A little diagramMortalityAs I was drawing out a little diagram see here, hopefully it helps others:
[https://docs.google.com/document/d/e/2PACX-1vTwGZIP5sBmxTu0XnqpEdoVEPRS8_3zf9jaMJ1oV7VEnuyV9uAfS7djqX09DTSEU-W8inMFAqEIAWXM/pub](https://docs.google.com/document/d/e/2PACX-1vTwGZIP5sBmxTu0XnqpEdoVEPRS8_3zf9jaMJ1oV7VEnuyV9uAfS7djqX09DTSEU-W8inMFAqEIAWXM/pub)
While I was doing this diagram I was thinking about how signals work, and I realized I'm not sure exactly sure what happens with _area parameter for the callback function _area_entered.
I assume the root node of the script just passes itself in? How does it do this? So the Area2D node that will be passed in is HealthPack? Would this be something like get_node('<root node>') or?
As a quick aside I'm also not sure the exact differences between when you can do:
_area_entered vs _area_entered()
I get the point of course that we are passing the function and don't want to call it, because _area_entered with '()' will expect 1 argument as per the function defintion.
Anyway when the _area_entered function is called it must have an Area2D shape, so I assume the root node is passed here as its the Area2D node. Though there is nothing to point at or draw to show this as was the case in my little diagram.
Again make ssense based on the warning for the argument for area with prepending '_' for _area_entered function as this is not actually used.10Mar. 12, 2024
area_that_entered parameter?HollowI still don't quite understand why the function we connect the signal to (_on_area_entered()) needs a parameter of type Area2d at all. Why does it need this parameter if it is not used in the function? Does it somehow pass on the parameter to the area_entered signal or the connect() function?80Mar. 09, 2024
Typo in signal callback function definitionRuben TeijeiroThere is a typo in the following code here in the lesson explanation:
func _on_area_entered(**area_that_entred**: Area2D) -> void:
It also appears below when adding queue_free().10Mar. 02, 2024
Code Reference: area_entered.connect(_on_area_entered)NorbertMy code: connect("area_entered", _on_area_entered)
Your Code: see title line
The result is the same! Is there a difference?20Mar. 02, 2024
Connecting Signals: Pitfalls?retronautConnecting signals via the UI reminds me of the IBOutlet connections that used to be the norm in connecting UI interactions to code in Apple's Xcode. Like you suggest in the lesson, it's often wiser (and more powerful) to set up these connections in code.
That being said, I'm curious what sorts of trouble (if any) you could get into by creating signal connections via the UI, removing the implementation, and forgetting to disconnect the signal. Or, alternatively, creating a signal in code and creating an identical or near identical connection via the UI.
In iOS, creating IBOutlets and forgetting to connect them - or disconnecting them and forgetting to remove them - was a frequent source of crashes and other headaches. Is that something we need to worry about here?10Mar. 01, 2024
Potential Error in L2.P1's InstructionsDumdomdeeIn the second paragraph of the instructions it mentions to open the scene pop_the_ball.tscn, however the description of the scene in the same paragraph seems to be instead referring to ball.tscn, unless I'm mistaken.
While the summary towards the end clears things up, it initially lead to a bit of confusion :p
Regardless thanks for the hard work on the course so far, looking forward to future modules!10Feb. 29, 2024
Area2D Signal to other ScenesXephireBetween the Enemy Scene the Player Scene, can you connect the signals such as area_entered and check which Group the Area2Ds are in? The Node Signal approach requires the creation of a connected function, but I was curious if this can be directly coded.
The Node Signals approach requires creation of this kind of function:
```gdscript
func _on_Area2D_area_entered(area):
if area.is_in_group("player_arm"):
print("My arm got hit!")
```30Feb. 29, 2024
Checkbox in L2.P1CloudeThe checkboxes are selectable in Chrome, but not in Firefox.
I think this "minor" problem appeared in this M5 release.10Feb. 26, 2024
Suggestion: Code should match indentation with godotedmunditoThe default indentation in Godot is a 1 tab/4 space indentation, but the code on the page is indented with two spaces, so I'm unable to copy and paste. Would it be possible to match the Godot default?10Feb. 25, 2024
Small typokpicazaHello, Hope you're doing well. I'm really enjoying the course and appreciate all the effort put into it. 😊 Just wanted to quickly point out a small typo I came across in the beginning of the lesson. The sentence, "Sprites are are great for displaying visuals that move," seems to have an extra "are." I believe it should be "Sprites are great for displaying visuals that move."
Thanks for creating such an insightful course.
Best regards,10Feb. 24, 2024
Pop the Ball > Run | Typo?KaiAfter running and completing the Pop the ball practice it says: "Congradulations! You aced this practice." Instead of: "Congratulations! You aced this practice." I'm just assuming that wasn't intentional.
Thanks for your hard work so far!10Feb. 24, 2024
L2.P1 The .tscn files already contain what was requiredMartinBSort of, I checked the ball scenes but they already had CollisionShape2D nodes in them as a child, but when I run it the lesson window says there's no collision nodes on them.
They're definitely there in the scenes, and they have shapes so I'm not sure what's going on.20Feb. 22, 2024
Connecting Timer signal with codeBaffledMcBundleHi Nathan,
Since we've learn how to connect signal with code I wanted to try connecting the timer signal that we used in the previous lessons with code. I can't wrap my head around this though.
I think it might be because with area_entered we connected the signal to the node that emits it, (I'm really not sure I make any sense here^^) whereas with timer we actually need to connect it with our ship node.
Anyway, when I try timeout.connect(_on_timer_timeout) I get an error saying "Identifier "timeout" not declared in the current scope." Is there a way to declare signals?
Thanks in advance for your time and answer :^)80Feb. 20, 2024
Singal is for any Area2D?BoomsquallyThe current code for the ball means that any other node that is an Area2D can make the balls disappear? Like, if there were two needles flying around, either of them could make the balls disappear. Is that correct?10Feb. 20, 2024
Typo in the practice instructions boxmq95Hi, there's a mistake in a sentence found in the practice instructions:
```gdscript
Detect in the ball in the script to detect when the triangle collides with the ball's Area2D.
```10Feb. 20, 2024
Connecting Signals: Small TypoRiskyPixels`func _on_area_entered(area_that_entred: Area2D) -> void:`
`pass`
I believe that the parameter was intended to read: "area_that_entered"
Thanks! 40Feb. 19, 2024
The ball has a circular collision shapeilliterate-spiderI have put child nodes on each ball. The nodes are all CollisionShape2D and the shape of the node is a CircleShape2D. The code is correct. I am getting the ball has a circular shape. The balls disappear but im still getting that in red. Help please =)70Feb. 19, 2024
Lesson Q&A
Use this space for questions related to what you're learning. For any other type of support (website, learning platform, payments, etc...) please get in touch using the contact form.