Ex-Unity user here. Just wanted to tell you that I was on the edge to go back to Unity after trying to get a signal between RayCast3D and an Animation player. Your tutorial was a life saver!
Duuuuude..... I've been trying to do something similar to this for over a week and have done it 27 different ways and finding this got it to work... you are a legend and have helped with a lot of stuff i've been busy with. You champion!!
so happy to hear!!! thank you so much!! it means the world!! I am so glad it was able to help you out!! if you ever need anything then please just let me know!
for those it may not be working for the "if body.has_method("Player"):" line in the enemy script is a way to check if a body enters does it have a func inside it named and in this case "player" so you can slap that into your player script for your enemy to detect and then transmit damage and its a unique func only to the player
Great job once again. As is tradition, some topic suggestions: camera that always pans slightly to where you are looking at, cutscenes where you move the player and an npc with animations, cutscenes with dialogue, updating your dash video from years ago to Godot 4 (fixed distance dash or some other type of dash).
@@dev-worm Thank you! Btw if you're working on the camera thing, please watch Game Maker's Toolkit video for reference: czcams.com/video/TdWFzpgnljs/video.html
The fact that I was watching the video without full screen and when he requested us to subscribe the subscribe button got a colorful border of neon colours for a fraction of seconda😅😅😅😅 I loved it 😂😂😂new feature huh
I just came over from your RPG tutorial series, and I have to say that while it sounds like you have gotten more confident in your videos, you are also talking and doing stuff a lot faster. I feel like the pacing would benefit from you taking your time a bit more. Other than that, great video!
thank you, yes you are correct.. i am working on trying to breakdown everything in newer videos.. this one was pretty quick and i didnt like it to much either.
There's the event bus pattern. I recently saw a quick video on it on a channel called SaltyTheGeek (name stuck out). Essentially, from what I understand: Make a singleton called EventBus In the singleton, put any signals you need or want In your listener object's ready function, connect its function to the EventBus signal you needed Lastly, when the conditions are met, use the caller object to emit EventBus.emit_signal("your_signsl_here", parameters_here) Edit: the other channel (Salty) gave basic code on a pastebin. There wasn't any explanation other than loose comments in the code. But I got value from it because I watched the implementation and was able to understand the comments.
I don't really get why you'd use has_method() and *then* call a signal on the object like that. That kind of feels like using signals to skirt around what is more or less already a bootleg interface pattern to me. (Bootleg only bc Godot forces us to duck type instead of using interfaces for some reason.) Just call the method, and stick to signals for bubbling up or global subscribable events that you don't want coupling on, this is adding extra complexity by using signals where they aren't needed.
Hey i love your videos u make everything so easy to understand . Can u please make a video about how to use this inventory plugin the documentation is quite hard to understand the plugin name is gloot v2.4.6 the latest version. i cannot send any links because my comments are being disappearing.
This was very good and valuable! Many thanks. If it is possible for you to talk slower, that would be appreciated. Beside that technical detail, good job!
thank you! Im sorry about the talking speed and I will note that for future videos as I understand how it can be hard to receive information that way!!
Thank you. I will subscribe. I hope to learn from your videos. My question is, do you narrate these tutorials all in one breath? XD Jokes. They're really good. I started with intro Python and great Godot learning course early this year and it's like emotional epilepsy. What did come to mind was one of my best breakthroughs for understanding python was "100 days of programing with Python" on Udemy. I did only 7 days that was somehow posted on youtube, but none the less, doing many small incremental quizzes help massively. If I was a great programmer I would make the same thing for Godot. But self drive and not hand holding is best of course.
This is a fantastic tutorial, thank you so much! Although im sure it wont bog it down too much, but instead of calling the update_health function in the process method, why not put it in the take damage method, outside of the if statement? Over all, the entire thing will update, and no need to call it every frame.
good call out! must have had a brain fart! sorry I have no idea why I did that lol.. seems silly! but thanks! and glad the rest of the tutorial was good lol
@@dev-worm I appreciate the videos you make, they're concise, to the point, and gives plenty of different explanations on when to use them, and how to use them. Please keep making more videos, cause I know they helped me a bunch, and I'm positive they'll help others too! BTW the brain fart happens, its all good lol
Can you make animations in one scene and then use signals to play them when an input is pressed in another scene? For example in your survival tutorial you have an arrow scene and before the arrow moves forward, during the charge (that I added to the bow where you have to hold the input for 1 second before an arrow flies) an animation is played where the arrow is pulled closer to the player and then it flies forward as described in your tutorial when the input is released.
could you clarify the significance of the signals and functions working together but passing differently-named variables? in example 3, the signal passes the variable "damage", and then the connection to that signal passes the function "damageAmount". I'm a bit confused about this part. how does Godot know what variable passes where when they're named differently? also, what is the practical purpose of being able to do this? (that is, why not just keep the names the same?)
I’ll split my answer into two parts to try to answer your questions better. Part 1 will be about how Godot handles differently named variables, and part 2 will be why this feature is useful. 1) You can think of the variable's names as placeholders for the useful information being passed through. Naming a variable just allows you to show the program what to do with it like to set the amount equal to 20 for damage or subtract that value from health. When the function take damage is called it only knows the inputs value regardless of what it’s named where the function is being called 2) In the example given there is no need for differently named variables as it was a very simple situation. In a more complex situation, you might have multiple different variables you would pass through depending on the current state, where you’d need more than 1 variable name so they couldn’t be the same. My answer was a bit longer and more complex than I’d like so let me know if you are still confused. I’m also not the most experienced at coding so anyone else please correct me if I explained anything incorrectly.
thanks for the detailed reply. regarding #1, I'm still confused about how Godot "knows" which variables are which in the case of multiple differently-named variables being passed. is it the order they appear in?@@hadesiguess8516
In addition to @hadesiguess8516 I just wanted to say that the way Godot knows which value to put in the renamed variable is by the order they are passed. So the first value passed will always go into the first variable and the second into the second etc.
I still dont get the point of custom signals. You couldve just called the method directly on the node. Ill use built in collision and control node signals but the custom ones still havent clicked with me.
@thesomeone2596 ok. For what? I'd love to know any "need" case. I have heard that you can't call methods of a node unless it's the child of the node, so you have to "signal up" but that isn't the case in the current godot version at least, you can call functions on any valid node that you can reference. I'm not saying there aren't use cases, I'm saying I haven't been able to find one that is simpler or better by another other metric Ive detected than just calling the method that is triggered by the signal I could've used.
You rarely NEED signals, but it's a very useful pattern that is easy to understand when it's triggered, as well as decoupling your code to maximize reusability and refactorability. Just think of all the built-in nodes. They all don't care about the other parts of your code because they use signals. So you can reuse those nodes as often as you like. This flexibility is achieved through the signal system. You can also google observer pattern or listener pattern, as that what signals actually are.
Needing a signal would be like a player object that is a child of the game world having a sibling that is the player's health bar. The health bar should not have anything to do with what's going on with the player's health, it just displays the value given to it. When the player's health changes, the player should emit a signal that is health changed, the new value, and whatever listeners are listening (the display) will do what it needs to do now that it has new information to work with.
Not sure if it’s optimal, but I emit a signal from certain creatures when the right timing/rng is met. This signal connects to the world/main and produces a dropped item given the location of the creature. Good example of this would be a chicken dropping an egg. Or a pig rooting up a mushroom. Or whatever. It’s abstracted to the point where the world has a function on_drop_resource that only needs an actor and a resource id.
Hey devWorm, amazing video but i didnt found what I was looking for so im asking in comments: I got a Pause Menu scene with buttons and script. I got the resume button to work but I cant figure out the exit button. After i click it I want it to queue free itself and the level im on and then I want the main node to add Main menu scene as its child so I can pick a gamemode again. How can I do it?
Need help clarifying something. I have a scene called ammo that I want to emit a signal to update a AnimatedSprite2D node. The AnimatedSprite2D node is a child node inside of a regular node, which is also a child node that's instance inside of my CharacterBody3D node (which I have saved as a player scene). I have a 3D node called world where both, ammo scene and player scene have been instantiated (I pressed the chain link icon in the scene window). How do I connect the signal through different nodes that are instantiated as a child scene? So imagine, in your second example, if the Example2Player has inside of it another node that I want to access.
Thanks for the tutorial passing variables in the signals very useful but what if we create a node in signal? if bullet_cooldown == false: var new_bullet = bullet.instantiate() new_bullet.global_position = global_position var dir = global_position.direction_to(body.global_position) direct.emit(dir) #new_bullet.direction_2 = dir #call_deferred("add_child",new_bullet) add_child(new_bullet) bullet_cooldown = true bullet node: func _ready(): $/root/World/Player.connect("direct",shoot) func shoot(direct): direction_2 = direct This code gives me 2 error. 1) It says: "E 0:00:01:0455 player.gd:48 @ _on_gun_range_body_entered(): Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead." whenever I spawn a bullet. 2) Bullets spawn when a enemy enter the range of player. But they don't move until another enemy moves in and only then it moves to closest enemy.
So, idk if you or anyone else can help me here. Idk if im just trying to brute force this the wrong way or what. SO, I set my first signal on my animation to "on animation finished("spawn")" for my spawn animation to transfer into the idle one. But it refuses to let me apply the same logic to the damage animation going back into the idle one. Any idea what im doing wrong? It seems like there's just one output per signal but that has to be wrong
hm, not sure what is going on. you should try and start looking into creating a player state machine, because once your player gets more complex having a state machine is going to make things a lot easier... for the issue you are having now I have no idea! Is there any errors? have you tried print checking to make sure it engine is running through the code successfully? I really dont know what could be the case I'm sorry!
Why do you create a method to identify bodies instead of defining groups? It makes no major difference as far as I can comprehend but it'd be good practice to define your bodies as part of a group and then use is_in_group to identify the body? Am I missing something?
no you are completely correct about that! unsure why I do it this way but thanks for pointing that out as I shouldnt be teaching this and I should be showing group and classes! thank you and sorry about this little hickup!
I have one question about signals, i have a player scene and a bullet scene. The bullet scene emits a signal if an area enters its area. So the question is how can i connect that signal to the ui, because the bullet is not in the scene it is instantiated with a button press ?
You can do it by code. If your bullet scene already has a script , probably in the bullet's _on_ready or_init() function, or another on that's called immediately after creation. Else, you can do it in the code that instanciates it, by connecting to the Bullet's Area2D (or whatever) 's signal. Not quite as clean as it requires other objects to "know" how missiles are built. The code would be something like : # if done in the bullet's script, "collided" is its signal declared in its script. self = the bullet, argument of UI's function on_bulley_hit(b : Bullet), Bullt being the bullet script's class_name. bullet_collided.connect(UI.on_bulley_hit.bind(self) ) # if done in the script that instanciated it : bullet.collided.connect(UI.on_bulley_hit.bind(bullet) ) # if bullet doesn't even have a script, assuming you use a Area2D and area_entered is the Area2D's signal. bullet.get_node("Area2DName").area_entered.connect(UI.on_bulley_hit.bind(bullet)) # with UI's on_bulley_hit(bullet : Sprite2D or Node2D or whatever)
On example 3 could I switch it around like instead of the enemy damaging the player could I use the same code but the player is the one damaging the enemy?
Indeed we have ways of slowing down if needed that’s good. But also kind of understand the comment up there. Might be good. In the end, the content is nice, thumbs up anyway.👍🏻
The way Godot uses signals is a wrong use of observer pattern. You should never have an object know their observer. To use correct observer patterns in Godot you should NOT use the signal emitting in the inspector; instead let your observers subscribe to the signal with code - Now your components are de-coupled aka they don't know about other components in your game = de-spaghettification and correct object oriented design.
Yeah I kind of noticed this myself when I tried to swap from Unity. I kinda prefer using a Bus pattern nowadays for most signals that aren't just bubbling up. Basically a singleton object that does nothing more than storing custom signals that other objects can call and subscribe to.
Hello, do you know of another way to pass arguments in built-in signals, like in the ‘pressed’ signal of a button? I found this method: button.pressed.connect(my_func.bind(my_arg)), but I’m curious if there’s another way
Ex-Unity user here. Just wanted to tell you that I was on the edge to go back to Unity after trying to get a signal between RayCast3D and an Animation player. Your tutorial was a life saver!
so happy to hear!! how's Godot been treating you??
@@dev-worm Good, for now. As I said, if you didn't made this super ex-Unity frendly tutorial, i would have gone back to Unity. thanks again!
Personally, as an Ex-Unity aswell, i like Signals so much more than Events
@@TheMegamanan Now I love them too, but I didn't understand them and now I feel a bit dumb...
Godot is not a Unity replacement though, but its nice to see you did not give up.
I appreciate how quickly you speak
You made me understand signals! Didn’t think I would be able to get it ^^
so happy to hear!! thank you so much!! that means for than the world to me!!!
I want you to know i appreciate you talking fast, my brain runs fast and everyone else is super slow.
i happy to hear that it was perfect for you!! thank you so much!! i am just so glad to help!
Duuuuude..... I've been trying to do something similar to this for over a week and have done it 27 different ways and finding this got it to work... you are a legend and have helped with a lot of stuff i've been busy with. You champion!!
so happy to hear!!! thank you so much!! it means the world!! I am so glad it was able to help you out!! if you ever need anything then please just let me know!
very helpful and clear! i heard 4 minutes and i figured it out thank you
so happy to hear that! glad I could help! thanks! if you ever need anything then please let me know!
Very well explained as always, keep up the great work!
thank you so much!! it means the world!!
it's my first time i've to slow down a video. :D btw great content
haha i’m sorry!! i hope it was still helpful!! thank you so much!! ❤️
Thank you man. This answered so many questions that I had. 🙏
so happy to hear that!!
Thanks, Devworm :) Just what I need to get a better understanding of signals! Can't wait to watch this later!
thank you, I'm happy to hear that! I hope the video is able to help you understand signals a bit better!
for those it may not be working for the "if body.has_method("Player"):" line in the enemy script is a way to check if a body enters does it have a func inside it named and in this case "player" so you can slap that into your player script for your enemy to detect and then transmit damage and its a unique func only to the player
Thanks DevWorm
of course! anytime!
Great job once again. As is tradition, some topic suggestions: camera that always pans slightly to where you are looking at, cutscenes where you move the player and an npc with animations, cutscenes with dialogue, updating your dash video from years ago to Godot 4 (fixed distance dash or some other type of dash).
working on dash as we speak. thanks for the ideas ill look into them more!
@@dev-worm Thank you! Btw if you're working on the camera thing, please watch Game Maker's Toolkit video for reference: czcams.com/video/TdWFzpgnljs/video.html
Thank you, love your guides! You've become one of my favorite Godot channels!
so happy to hear that, glad im able to help.. if you ever need anything then please let me know!
This is just what I needed! Thank you!🙏
Glad it was helpful!
man i love your videos
thanks bro!! it means the world!!
Thanks man. Needed this
so happy to hear that!
You have no idea how long I have been searching for the answers that are well given in this video lol
so happy to hear!! thanks!
The fact that I was watching the video without full screen and when he requested us to subscribe the subscribe button got a colorful border of neon colours for a fraction of seconda😅😅😅😅 I loved it 😂😂😂new feature huh
ah really?? must be.. that seems cool lol
Very useful. Next research step is to understand how to pass these through an Event Handler script so I can scale my game and make multiple instances
I just came over from your RPG tutorial series, and I have to say that while it sounds like you have gotten more confident in your videos, you are also talking and doing stuff a lot faster. I feel like the pacing would benefit from you taking your time a bit more. Other than that, great video!
thank you, yes you are correct.. i am working on trying to breakdown everything in newer videos.. this one was pretty quick and i didnt like it to much either.
This is exactly what I needed, thank you so much!
happy to hear that! thank you!
Thanks for the tutorial, but what is the best way of connecting a signal emitted by another scene?
There's the event bus pattern. I recently saw a quick video on it on a channel called SaltyTheGeek (name stuck out).
Essentially, from what I understand:
Make a singleton called EventBus
In the singleton, put any signals you need or want
In your listener object's ready function, connect its function to the EventBus signal you needed
Lastly, when the conditions are met, use the caller object to emit EventBus.emit_signal("your_signsl_here", parameters_here)
Edit: the other channel (Salty) gave basic code on a pastebin. There wasn't any explanation other than loose comments in the code. But I got value from it because I watched the implementation and was able to understand the comments.
Good stuff! Thanks
thank you so much!!
thanks for the tutorial!
of course anytime!
I don't really get why you'd use has_method() and *then* call a signal on the object like that. That kind of feels like using signals to skirt around what is more or less already a bootleg interface pattern to me. (Bootleg only bc Godot forces us to duck type instead of using interfaces for some reason.) Just call the method, and stick to signals for bubbling up or global subscribable events that you don't want coupling on, this is adding extra complexity by using signals where they aren't needed.
He's just teaching horrible practices because he doesn't understand what he's doing himself.
Hey i love your videos u make everything so easy to understand . Can u please make a video about how to use this inventory plugin the documentation is quite hard to understand
the plugin name is gloot v2.4.6 the latest version. i cannot send any links because my comments are being disappearing.
ill check it out, thanks!!
@@dev-worm Thanks!!!
super helpful, thanks!
thank you so much!!! glad it was helpful!!
This was very good and valuable! Many thanks. If it is possible for you to talk slower, that would be appreciated. Beside that technical detail, good job!
thank you! Im sorry about the talking speed and I will note that for future videos as I understand how it can be hard to receive information that way!!
Thank you. I will subscribe.
I hope to learn from your videos. My question is, do you narrate these tutorials all in one breath? XD Jokes. They're really good.
I started with intro Python and great Godot learning course early this year and it's like emotional epilepsy.
What did come to mind was one of my best breakthroughs for understanding python was "100 days of programing with Python" on Udemy. I did only 7 days that was somehow posted on youtube, but none the less, doing many small incremental quizzes help massively. If I was a great programmer I would make the same thing for Godot. But self drive and not hand holding is best of course.
MCSquirmy the Legend!
@MochiRosu the Legend!
Thanks for the videos brother, could you bring a video explaining how to enter/use some type of vehicle? whether horse, car, etc.
You are the best!
thank you so much, youve just made my day! If you ever need any help with Godot then please let me know!
This is a fantastic tutorial, thank you so much!
Although im sure it wont bog it down too much, but instead of calling the update_health function in the process method, why not put it in the take damage method, outside of the if statement? Over all, the entire thing will update, and no need to call it every frame.
good call out! must have had a brain fart! sorry I have no idea why I did that lol.. seems silly! but thanks! and glad the rest of the tutorial was good lol
@@dev-worm I appreciate the videos you make, they're concise, to the point, and gives plenty of different explanations on when to use them, and how to use them. Please keep making more videos, cause I know they helped me a bunch, and I'm positive they'll help others too! BTW the brain fart happens, its all good lol
thanks!
of course anytime! thank you!
Can you make animations in one scene and then use signals to play them when an input is pressed in another scene?
For example in your survival tutorial you have an arrow scene and before the arrow moves forward, during the charge (that I added to the bow where you have to hold the input for 1 second before an arrow flies) an animation is played where the arrow is pulled closer to the player and then it flies forward as described in your tutorial when the input is released.
Yea it sounds totally possible
Hello DevWorm!
Your video is really helpful.
Hope you can guide me on how to make a roguelike game like Brotato!
hey thank you so much! I'm actually working on a rogue like game tutorial series right now!
@@dev-worm Great! I look forward to it
I was trying to use the connect method to connect "open" signal to chests in multiply level scenes. Never go it to work right.
could you clarify the significance of the signals and functions working together but passing differently-named variables? in example 3, the signal passes the variable "damage", and then the connection to that signal passes the function "damageAmount". I'm a bit confused about this part. how does Godot know what variable passes where when they're named differently? also, what is the practical purpose of being able to do this? (that is, why not just keep the names the same?)
I’ll split my answer into two parts to try to answer your questions better. Part 1 will be about how Godot handles differently named variables, and part 2 will be why this feature is useful.
1) You can think of the variable's names as placeholders for the useful information being passed through. Naming a variable just allows you to show the program what to do with it like to set the amount equal to 20 for damage or subtract that value from health. When the function take damage is called it only knows the inputs value regardless of what it’s named where the function is being called
2) In the example given there is no need for differently named variables as it was a very simple situation. In a more complex situation, you might have multiple different variables you would pass through depending on the current state, where you’d need more than 1 variable name so they couldn’t be the same.
My answer was a bit longer and more complex than I’d like so let me know if you are still confused. I’m also not the most experienced at coding so anyone else please correct me if I explained anything incorrectly.
@@hadesiguess8516 that is a very good explanation of it
thanks for the detailed reply. regarding #1, I'm still confused about how Godot "knows" which variables are which in the case of multiple differently-named variables being passed. is it the order they appear in?@@hadesiguess8516
In addition to @hadesiguess8516 I just wanted to say that the way Godot knows which value to put in the renamed variable is by the order they are passed. So the first value passed will always go into the first variable and the second into the second etc.
I still dont get the point of custom signals. You couldve just called the method directly on the node. Ill use built in collision and control node signals but the custom ones still havent clicked with me.
If you continue using godot there will be a time where you gonna need them
@thesomeone2596 ok. For what? I'd love to know any "need" case. I have heard that you can't call methods of a node unless it's the child of the node, so you have to "signal up" but that isn't the case in the current godot version at least, you can call functions on any valid node that you can reference. I'm not saying there aren't use cases, I'm saying I haven't been able to find one that is simpler or better by another other metric Ive detected than just calling the method that is triggered by the signal I could've used.
You rarely NEED signals, but it's a very useful pattern that is easy to understand when it's triggered, as well as decoupling your code to maximize reusability and refactorability.
Just think of all the built-in nodes. They all don't care about the other parts of your code because they use signals. So you can reuse those nodes as often as you like. This flexibility is achieved through the signal system. You can also google observer pattern or listener pattern, as that what signals actually are.
Needing a signal would be like a player object that is a child of the game world having a sibling that is the player's health bar. The health bar should not have anything to do with what's going on with the player's health, it just displays the value given to it. When the player's health changes, the player should emit a signal that is health changed, the new value, and whatever listeners are listening (the display) will do what it needs to do now that it has new information to work with.
Not sure if it’s optimal, but I emit a signal from certain creatures when the right timing/rng is met. This signal connects to the world/main and produces a dropped item given the location of the creature. Good example of this would be a chicken dropping an egg. Or a pig rooting up a mushroom. Or whatever. It’s abstracted to the point where the world has a function on_drop_resource that only needs an actor and a resource id.
In example2, why not just have one signal and pass the colour as a parameter?
Hey devWorm, amazing video but i didnt found what I was looking for so im asking in comments: I got a Pause Menu scene with buttons and script. I got the resume button to work but I cant figure out the exit button. After i click it I want it to queue free itself and the level im on and then I want the main node to add Main menu scene as its child so I can pick a gamemode again. How can I do it?
thanks
Need help clarifying something. I have a scene called ammo that I want to emit a signal to update a AnimatedSprite2D node.
The AnimatedSprite2D node is a child node inside of a regular node, which is also a child node that's instance inside of my CharacterBody3D node (which I have saved as a player scene). I have a 3D node called world where both, ammo scene and player scene have been instantiated (I pressed the chain link icon in the scene window). How do I connect the signal through different nodes that are instantiated as a child scene?
So imagine, in your second example, if the Example2Player has inside of it another node that I want to access.
Thanks for the tutorial passing variables in the signals very useful but what if we create a node in signal?
if bullet_cooldown == false:
var new_bullet = bullet.instantiate()
new_bullet.global_position = global_position
var dir = global_position.direction_to(body.global_position)
direct.emit(dir)
#new_bullet.direction_2 = dir
#call_deferred("add_child",new_bullet)
add_child(new_bullet)
bullet_cooldown = true
bullet node:
func _ready():
$/root/World/Player.connect("direct",shoot)
func shoot(direct):
direction_2 = direct
This code gives me 2 error.
1) It says:
"E 0:00:01:0455 player.gd:48 @ _on_gun_range_body_entered(): Can't change this state while flushing queries. Use call_deferred() or set_deferred() to change monitoring state instead." whenever I spawn a bullet.
2) Bullets spawn when a enemy enter the range of player. But they don't move until another enemy moves in and only then it moves to closest enemy.
So, idk if you or anyone else can help me here. Idk if im just trying to brute force this the wrong way or what.
SO, I set my first signal on my animation to "on animation finished("spawn")" for my spawn animation to transfer into the idle one. But it refuses to let me apply the same logic to the damage animation going back into the idle one. Any idea what im doing wrong? It seems like there's just one output per signal but that has to be wrong
hm, not sure what is going on. you should try and start looking into creating a player state machine, because once your player gets more complex having a state machine is going to make things a lot easier... for the issue you are having now I have no idea! Is there any errors? have you tried print checking to make sure it engine is running through the code successfully? I really dont know what could be the case I'm sorry!
Why do you create a method to identify bodies instead of defining groups? It makes no major difference as far as I can comprehend but it'd be good practice to define your bodies as part of a group and then use is_in_group to identify the body? Am I missing something?
no you are completely correct about that! unsure why I do it this way but thanks for pointing that out as I shouldnt be teaching this and I should be showing group and classes! thank you and sorry about this little hickup!
@@dev-worm no worries, thanks for the clarification!
I have one question about signals, i have a player scene and a bullet scene. The bullet scene emits a signal if an area enters its area.
So the question is how can i connect that signal to the ui, because the bullet is not in the scene it is instantiated with a button press ?
You can do it by code.
If your bullet scene already has a script , probably in the bullet's _on_ready or_init() function, or another on that's called immediately after creation.
Else, you can do it in the code that instanciates it, by connecting to the Bullet's Area2D (or whatever) 's signal. Not quite as clean as it requires other objects to "know" how missiles are built.
The code would be something like :
# if done in the bullet's script, "collided" is its signal declared in its script. self = the bullet, argument of UI's function on_bulley_hit(b : Bullet), Bullt being the bullet script's class_name.
bullet_collided.connect(UI.on_bulley_hit.bind(self) )
# if done in the script that instanciated it :
bullet.collided.connect(UI.on_bulley_hit.bind(bullet) )
# if bullet doesn't even have a script, assuming you use a Area2D and area_entered is the Area2D's signal.
bullet.get_node("Area2DName").area_entered.connect(UI.on_bulley_hit.bind(bullet))
# with UI's on_bulley_hit(bullet : Sprite2D or Node2D or whatever)
you could use a autoload singleton script and store you custom signals in that, that way dynamic loaded objects can communicate more easily.
On example 3 could I switch it around like instead of the enemy damaging the player could I use the same code but the player is the one damaging the enemy?
bro there is one issue you teach so fast and i am a beginner i need some time
sorry bro! if there was anything you couldnt understand feel free to ask me! Im sorry it was all a little to quick!
talk slower!
okay! sorry, ill try!
No, don’t! ❤
Playback 0.75 worked for me.
Indeed we have ways of slowing down if needed that’s good. But also kind of understand the comment up there. Might be good.
In the end, the content is nice, thumbs up anyway.👍🏻
Definitely talk slower, wtf. Lol
The way Godot uses signals is a wrong use of observer pattern. You should never have an object know their observer.
To use correct observer patterns in Godot you should NOT use the signal emitting in the inspector; instead let your observers subscribe to the signal with code - Now your components are de-coupled aka they don't know about other components in your game = de-spaghettification and correct object oriented design.
Yeah I kind of noticed this myself when I tried to swap from Unity.
I kinda prefer using a Bus pattern nowadays for most signals that aren't just bubbling up. Basically a singleton object that does nothing more than storing custom signals that other objects can call and subscribe to.
Decent Tutorial but damn slow down.
i do apologize!! hope you were still able to get the information from it!
@dev-worm I do appreciate the effort and time it is hard to put yourself out there. Was just a little paced with your fast brain vs us slower people.
Hello, do you know of another way to pass arguments in built-in signals, like in the ‘pressed’ signal of a button? I found this method: button.pressed.connect(my_func.bind(my_arg)), but I’m curious if there’s another way
when connecting the signal 3:23 click on advanced, and you can add arguments