Holy cow, I have spent two days trying to understand how to connect my nodes with code and you explained better in 3 minutes than most 30 minute videos. Thank you!
This is well explained, but I have a critique on presentation. For other videos like this, can you crop and zoom into your code? Most of the screen space you show during the coding part is unused and doesn't need to be there. If you deleted it, you could show the code bigger on screen. I watched this on a phone, and could barely read it.
Thank you for the feedback. I agree! In some later videos, I started showing the code only and cropping out the other parts of Godot's editor; I will make sure to keep that in mind and prioritize readability : )
I like the format of the flow charts and animations to future drive the concepts. Request: can you do a (simple) finite state machine using a node based approach. Example characterbody2d as the parent, STATE machine node, then node of each additional state. For some reason i am trying to wrap my head around this concept and i think your approach would clarify this concept.
@@brabes76 Are you referring to something like this: `CharacterBody2D (Parent) |-- idleStateNode |-- walkingStateNode...` And the script of the CharacterBody2D contains the logic that handles the character's state transitions, right?
Very good explaination, I seriously think this should be recommended to everyone trying to learn Godot, 3 short minutes and BAM, you already know how signals work !
You didn't mention that custom signals are mandatory when you need to emit a signal from a scene into another scene. For example, the player enters a house inside a level scene, the house scene has an area2d to detect the player, and now you need to change the level scene in the player is in from outside to inside. The area2d entered signal needs to be re-emitted by the house scene as a custom signal, so you can connect the level manager to know that now it should change scene.
Really well done only note would be to place your explanation images within the black space of the script editor portion so the actual code / editor can be seen clearer.
Thank you for this video. It puts together all the puzzle pieces in my mind. I understood how to create a custom signal and I knew I would emit it in the same script. but now i understand how to connect it to a function. sweeeet!!
New to Godot and game engines in general but signals remind me a lot of the event object in JavaScript. Seems like a significantly more efficient way of doing things rather than running an IF statement on every loop of the game engine. I was pleased to see Godot had a feature like this and it's easy to use.
I have to find more videos like this and less full tutorials, I think. Great work, thank you. It would be nice if the sub-window containing your script was bigger. Otherwise, liked the visuals.
@@trashy_fgc I feel like signals give the vibes of a message being received, so I tried to use a sound effect that give this feeling. It turns out, it was not a very smart move : ( I will make sure to use other sound effects for future videos.
@@toddlask Yes, for sure! - There is this video about scene and scene instanation: ruclips.net/video/NwpCjyoNYHA/видео.html - I also added another one on the todo list, that should go over more stuff you can do with scenes in GDscript(eg. changing scenes)
Yes, you can connect a signal from the (root) of a scene to a method on one of its sub-nodes (children). Actually, you can connect a signal on a node, to a method of another node, as long as both nodes are in the scene tree.
@@JumboGamedev So when I want to send signals from one child of scene A to a child of scene B, where scenes A and B are siblings in the main scene, I have to search the parent scene (common scene of A and B) for scene B and connect to the root node of scene B, after which I delegate the call to scene B's children (via tree search, casting, and function calls, or again with new signals)? Is there any other/better way? One use case would be to have the game in scene A and the UI in scene B, e.g.!
you can do it in the UI by right clicking on scene A -> check editable children. This will expose the children of scene A (in the main scene), you can do the same to scene B, and connect the children you want to wire together from the UI, like any other signal. Or You might connect them in code directly (get a reference to the child of scene A and the child of scene B. One way to do it is by starting at the root of the main scene or the root viewport (get_node('/root/....') # replace `....` with your path). Once you have access to the node references you can do the connection).
@@martinmajewskior you could create an SignalBus singleton that manages signals globally. Implemented this in C# to programmatically make signals with signatures.
Question: can you send signals from other scenes that are in said level tree? For example you create an object scene that has its own specific nodes and scripts, but has unique signals that need to be sent to the player/other game object in order for it to work. Do you need to get a reference to the scene and connect the object that you want to subscribe to the signal?
As you implied, one way is to use the get_node function to get a reference to the scene and connect to the signal. But there are other ways. For example, you can delegate the signal to a common parent (ie. a common parent, like the root of the scene that contains both instances, would receive the signal and this root node would invoke a method on the player/other game node). Another way is to use an autoload, which would contain some signals, and nodes can conveniently connect to the signal they want.
I am so angry. Why can't I connect a signal to a different scene from the code inside a scene that emits it? It was such a simple task in Godot 3, but now I can't find a solution. And why would I ever need to connect a signal to the same scene? There are no tasks that require it
You can connect to a signal emitted by a node that exists in another scene. If I remember correctly, doing something like that is similar in both Godot 3 and 4. Connecting a signal to another node in the same scene could be handy in some cases; for example, if you want multiple nodes in the same scene to react to a change/event that happened to another node in the same scene.
How about an example of connecting a signal when nodes are not siblings of one another, such as a scene that is instantiated during the game? Is there also a good way to connect a signal from one instantiated scene to another instantiated scene, both being created at different times during the game?
Yes, you can. You can do the connection through code, when you are instantiating the later scene. For example, assume you have 3 scenes: - main scene (instantiates both scene A and B at different times during the game) - scene A (has the node that emits the signal) - scene B (has the node that should emit the signal) In the script of one of the nodes in the main scene, get a reference to the node that emits the signal in scene A and the node that should receive the signal in scene B. (One way to do it is by starting at the root of the main scene or the root viewport (get_node('/root/....') # replace `....` with your path), then you can do the connection.
@@JumboGamedev I will try this sometime this week when I have development time and see how it goes. I think I understand, but I need to try it myself by writing code. I really appreciate the explanation!
@@JumboGamedevthat seems like coupling, no? I feel that signals are not intended to be used like an event system just a convoluted way to call a method on another node for which you already have a reference to
@@TriteanRaresYeah best way I found a way around coupling connectors is to have a global EventBus written in C# where you can programmatically add user defined signals with call signatures then connect callables to the EventBus’s signal. Its a singleton pattern but it gets the job done so Im not complaining :)
@@TriteanRares Yes I agree, this adds coupling, which wouldn't scale too well. Generally, If node A wants another distant node B to do something, I delegate the message to a common ancestor (using signals), and this ancestor should invoke a function on the node B. (BTW. by distant node, I mean a node that is not a descendant or an ancestor of node A) Might not be a perfect solution if you have to do this for a lot of nodes. But most of the time I try to keep related nodes close to each other to avoid jumping around the scene tree. @dr.positive mentioned a nice solution. I have seen this pattern, and it works great, for large projects. You can even combine both patterns and have multiple event buses on different levels of your scene tree.
So. Signal = Pizza on the menu Connect = Someone who wants to eat pizza Function and emit = The restaurant makes some eatable things that will be called pizza. Is this correct? I'm trying to understand the concept here. 😅😅
Interesting analogy :) . I may put it this way: - A signal = is the event that a pizza has been cooked. - connect = You are telling the restaurant to let you know/notify you everytime a pizza has been cooked (ie. the restaurant sends you a message/notification that let's you know the pizza has been cooked). - emit = Everytime the restaurant makes a pizza, it let's us know/notifies us that a new pizza has been made. The reason it notifies us, is because we are connected to this signal. (ie. we asked the restaurant to send a message/notification when it cooks a pizza when we used the connect method) In the same sense assume you have 2 nodes: - button node: this acts as the restaurant that will notify us when something happens. - another node: this acts as the listener/ person waiting for the button node to say something. A similar scenario could be: - A signal: is the event button is clicked - connect: the other node asks the button node to notify it when someone clicks the button. - emit: someone has clicked the button, so in response the button node will make sure to notify the other node that someone has clicked the button. When the button node emits the signal, the other node will make sure to react by executing the function that you have defined.
@@JumboGamedev Thank you, I have more questions😅 1. So a signal and the emit must be used together all the time, right? It would be pointless if we have a signal but don't emit it? 2. "When the event button is clicked" Can I write this on other nodes as well? I mean In case I don't want to use signal but I want another node to have the "When the event button is clicked" and act exactly the same. Is there another way to get the pizza from the shop without a connection and the signal?
@@TheBoEoSoT 1) For custom signals, yes, it would be pointless to define a signal that is never emitted it. 2) If I understand correctly, you want to execute a function when a button is clicked without using a connection and a signal? If this is what you want, I think there may be convoluted and inefficient ways like constantly checking the state of the button in the _process function. But using a signal would be much better for this case.
A mix of blender and after effects. (In the past, I used after effects only). OBS (for recording), audacity (for audio), davinci resolve (for editing). : )
Holy cow, I have spent two days trying to understand how to connect my nodes with code and you explained better in 3 minutes than most 30 minute videos. Thank you!
You are welcome. Thank you!
This is well explained, but I have a critique on presentation. For other videos like this, can you crop and zoom into your code? Most of the screen space you show during the coding part is unused and doesn't need to be there. If you deleted it, you could show the code bigger on screen. I watched this on a phone, and could barely read it.
Thank you for the feedback. I agree! In some later videos, I started showing the code only and cropping out the other parts of Godot's editor; I will make sure to keep that in mind and prioritize readability : )
@@JumboGamedev Oh, good to know! I just switched from Unity to Godot, so I'll check those out. Thank you!
@@Dracalis You are very welcome : )
I like the format of the flow charts and animations to future drive the concepts.
Request: can you do a (simple) finite state machine using a node based approach. Example characterbody2d as the parent, STATE machine node, then node of each additional state. For some reason i am trying to wrap my head around this concept and i think your approach would clarify this concept.
@@brabes76 Are you referring to something like this:
`CharacterBody2D (Parent)
|-- idleStateNode
|-- walkingStateNode...`
And the script of the CharacterBody2D contains the logic that handles the character's state transitions, right?
Really nice and succint. All the information needed to understand signals! Thank you!!!
Thank you!!! 🙂
The animations really add a nice feel to the video as well. I agree
@@w花b Thank you!
Very good explaination, I seriously think this should be recommended to everyone trying to learn Godot, 3 short minutes and BAM, you already know how signals work !
Thank you, much appreciated!
You didn't mention that custom signals are mandatory when you need to emit a signal from a scene into another scene. For example, the player enters a house inside a level scene, the house scene has an area2d to detect the player, and now you need to change the level scene in the player is in from outside to inside. The area2d entered signal needs to be re-emitted by the house scene as a custom signal, so you can connect the level manager to know that now it should change scene.
Good note! Thank you for sharing!
I love how casually you used PI, such elegance!
This was so cool🤩🤩
Please continue and don't stop ❤
Thank you! ❤
Thank you so much.
Was having so much trouble with this.
You are very very welcome 😁
Really well done only note would be to place your explanation images within the black space of the script editor portion so the actual code / editor can be seen clearer.
Thank you for the feedback!
thanks - it helped me understand the new Signals syntax better.
You are welcome!
Thank you for this video. It puts together all the puzzle pieces in my mind. I understood how to create a custom signal and I knew I would emit it in the same script. but now i understand how to connect it to a function. sweeeet!!
You are very welcome! Glad you enjoyed the video!
That was the best tutorial I've ever seen!
Thank you very much!
New to Godot and game engines in general but signals remind me a lot of the event object in JavaScript. Seems like a significantly more efficient way of doing things rather than running an IF statement on every loop of the game engine. I was pleased to see Godot had a feature like this and it's easy to use.
Me too. I always feel like Godot has a lot of similarities with DOM and events.
@@JumboGamedev Observer pattern rules!
Thanks this is awesome! I love connecting via Code
Thank you very much!
this helps a lot to understand how signals works in Godot..great video!
Thank you : )
I really like the way you teach!
Thank you!
Awesome tutorial! Can you make a video on how to implement background loading in Godot 4 with a loading screen?
For sure! I added it to the Todo list : )
I didnt know you can define custom signals, that should be pretty useful, for example double click or long press.
Great tut!
Thank you!
i like the graphics, hel[ped solidify my previous knowledge of signals. thank you.
code was a little small even on laptop. bump up scale by +10-25%
Thank you for the feedback. I agree! In some later videos, I adjusted the scale to make the text more visible.
Good job 👍
Thank you 👍
I have to find more videos like this and less full tutorials, I think. Great work, thank you. It would be nice if the sub-window containing your script was bigger. Otherwise, liked the visuals.
Thank you!
keep doing
Great tutorial!
Thank you : )
Kept glancing at my Gchat window thinking folks were messaging me throughout hahahaha
no one messaged me...
@@trashy_fgc I feel like signals give the vibes of a message being received, so I tried to use a sound effect that give this feeling. It turns out, it was not a very smart move : ( I will make sure to use other sound effects for future videos.
@@JumboGamedevnot a complaint at all just funny haha
@@trashy_fgc It reminds me of a sound effect of a knocking door I heard some time ago xD
nice job!
Thank you :)
@@JumboGamedev maybe u could do a video on the node tree? and how to mess w it in code.instantiating scenes. stay cool!
@@toddlask Yes, for sure!
- There is this video about scene and scene instanation: ruclips.net/video/NwpCjyoNYHA/видео.html
- I also added another one on the todo list, that should go over more stuff you can do with scenes in GDscript(eg. changing scenes)
@@JumboGamedev cool thx
Great tutorial! Is it possible to emit and connect signals to different nodes?
Thank you! Yes, it is possible to emit and connect signals to different nodes.
This is gold
Thank you!
Deserves a lot more subs
Thank you! : )
Thanks
You are welcome : )
nice!
Thank you very much!
Great Video! Can you give the name of the editor you used?
Thank you! I used davinci resolve to do the edits for the video, and I used audacity to do the edits for the audio. Is that what you meant by editor?
thx
You are welcome!
What about connecting signals to methods between scenes and scene sub-nodes?
Yes, you can connect a signal from the (root) of a scene to a method on one of its sub-nodes (children). Actually, you can connect a signal on a node, to a method of another node, as long as both nodes are in the scene tree.
@@JumboGamedev So when I want to send signals from one child of scene A to a child of scene B, where scenes A and B are siblings in the main scene, I have to search the parent scene (common scene of A and B) for scene B and connect to the root node of scene B, after which I delegate the call to scene B's children (via tree search, casting, and function calls, or again with new signals)? Is there any other/better way? One use case would be to have the game in scene A and the UI in scene B, e.g.!
you can do it in the UI by right clicking on scene A -> check editable children. This will expose the children of scene A (in the main scene),
you can do the same to scene B, and connect the children you want to wire together from the UI, like any other signal.
Or
You might connect them in code directly (get a reference to the
child of scene A and the child of scene B. One way to do it is by starting at the root of the main scene or the root viewport (get_node('/root/....') # replace `....` with your path). Once you have access to the node references you can do the connection).
@@martinmajewskior you could create an SignalBus singleton that manages signals globally. Implemented this in C# to programmatically make signals with signatures.
Question: can you send signals from other scenes that are in said level tree? For example you create an object scene that has its own specific nodes and scripts, but has unique signals that need to be sent to the player/other game object in order for it to work. Do you need to get a reference to the scene and connect the object that you want to subscribe to the signal?
As you implied, one way is to use the get_node function to get a reference to the scene and connect to the signal. But there are other ways. For example, you can delegate the signal to a common parent (ie. a common parent, like the root of the scene that contains both instances, would receive the signal and this root node would invoke a method on the player/other game node). Another way is to use an autoload, which would contain some signals, and nodes can conveniently connect to the signal they want.
I don't think we need to make a signal for fullrotation unless there's other node listen to sprite signal. Nevertheless it's a good tutorial
Thank you!
I am so angry. Why can't I connect a signal to a different scene from the code inside a scene that emits it? It was such a simple task in Godot 3, but now I can't find a solution. And why would I ever need to connect a signal to the same scene? There are no tasks that require it
You can connect to a signal emitted by a node that exists in another scene. If I remember correctly, doing something like that is similar in both Godot 3 and 4.
Connecting a signal to another node in the same scene could be handy in some cases; for example, if you want multiple nodes in the same scene to react to a change/event that happened to another node in the same scene.
but what's the music in the video?
Stark Goes Dark - The Whole Other
How about an example of connecting a signal when nodes are not siblings of one another, such as a scene that is instantiated during the game? Is there also a good way to connect a signal from one instantiated scene to another instantiated scene, both being created at different times during the game?
Yes, you can. You can do the connection through code, when you are instantiating the later scene.
For example, assume you have 3 scenes:
- main scene (instantiates both scene A and B at different times during the game)
- scene A (has the node that emits the signal)
- scene B (has the node that should emit the signal)
In the script of one of the nodes in the main scene, get a reference to the node that emits the signal in scene A and the node that should receive the signal in scene B. (One way to do it is by starting at the root of the main scene or the root viewport (get_node('/root/....') # replace `....` with your path), then you can do the connection.
@@JumboGamedev I will try this sometime this week when I have development time and see how it goes. I think I understand, but I need to try it myself by writing code. I really appreciate the explanation!
@@JumboGamedevthat seems like coupling, no? I feel that signals are not intended to be used like an event system just a convoluted way to call a method on another node for which you already have a reference to
@@TriteanRaresYeah best way I found a way around coupling connectors is to have a global EventBus written in C# where you can programmatically add user defined signals with call signatures then connect callables to the EventBus’s signal. Its a singleton pattern but it gets the job done so Im not complaining :)
@@TriteanRares Yes I agree, this adds coupling, which wouldn't scale too well. Generally, If node A wants another distant node B to do something, I delegate the message to a common ancestor (using signals), and this ancestor should invoke a function on the node B. (BTW. by distant node, I mean a node that is not a descendant or an ancestor of node A)
Might not be a perfect solution if you have to do this for a lot of nodes. But most of the time I try to keep related nodes close to each other to avoid jumping around the scene tree.
@dr.positive mentioned a nice solution. I have seen this pattern, and it works great, for large projects.
You can even combine both patterns and have multiple event buses on different levels of your scene tree.
So.
Signal = Pizza on the menu
Connect = Someone who wants to eat pizza
Function and emit = The restaurant makes some eatable things that will be called pizza.
Is this correct? I'm trying to understand the concept here. 😅😅
Interesting analogy :) . I may put it this way:
- A signal = is the event that a pizza has been cooked.
- connect = You are telling the restaurant to let you know/notify you everytime a pizza has been cooked (ie. the restaurant sends you a message/notification that let's you know the pizza has been cooked).
- emit = Everytime the restaurant makes a pizza, it let's us know/notifies us that a new pizza has been made. The reason it notifies us, is because we are connected to this signal. (ie. we asked the restaurant to send a message/notification when it cooks a pizza when we used the connect method)
In the same sense assume you have 2 nodes:
- button node: this acts as the restaurant that will notify us when something happens.
- another node: this acts as the listener/ person waiting for the button node to say something.
A similar scenario could be:
- A signal: is the event button is clicked
- connect: the other node asks the button node to notify it when someone clicks the button.
- emit: someone has clicked the button, so in response the button node will make sure to notify the other node that someone has clicked the button.
When the button node emits the signal, the other node will make sure to react by executing the function that you have defined.
@@JumboGamedev Thank you, I have more questions😅
1. So a signal and the emit must be used together all the time, right? It would be pointless if we have a signal but don't emit it?
2. "When the event button is clicked" Can I write this on other nodes as well? I mean In case I don't want to use signal but I want another node to have the "When the event button is clicked" and act exactly the same. Is there another way to get the pizza from the shop without a connection and the signal?
@@TheBoEoSoT
1) For custom signals, yes, it would be pointless to define a signal that is never emitted it.
2) If I understand correctly, you want to execute a function when a button is clicked without using a connection and a signal?
If this is what you want, I think there may be convoluted and inefficient ways like constantly checking the state of the button in the _process function. But using a signal would be much better for this case.
@@JumboGamedevwow, thank you very much for your answer. you're the best.
@@TheBoEoSoT You are very welcome. Thank you very much 😁
so signals = events?
Yes, they are very similar concepts.
Dude.. your message notification sound gives my anxiety, anxiety. Otherwise good overview
Not my intention at all, I will make sure to use a different sound effect for future videos.
Thank you : )
Pleasant animations. What do you use to make them?
A mix of blender and after effects. (In the past, I used after effects only).
OBS (for recording), audacity (for audio), davinci resolve (for editing). : )
wysi likes
Thank you!