How to Use SIGNALS Correctly in Godot 4 (everything to know)

Sdílet
Vložit
  • čas přidán 22. 08. 2024

Komentáře • 126

  • @AndyAndrewEntertaiment
    @AndyAndrewEntertaiment Před 4 měsíci +28

    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!

    • @dev-worm
      @dev-worm  Před 4 měsíci +5

      so happy to hear!! how's Godot been treating you??

    • @AndyAndrewEntertaiment
      @AndyAndrewEntertaiment Před 4 měsíci +3

      @@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!

    • @TheMegamanan
      @TheMegamanan Před 4 měsíci +2

      Personally, as an Ex-Unity aswell, i like Signals so much more than Events

    • @AndyAndrewEntertaiment
      @AndyAndrewEntertaiment Před 4 měsíci +1

      @@TheMegamanan Now I love them too, but I didn't understand them and now I feel a bit dumb...

    • @YoshimiMilk
      @YoshimiMilk Před 4 měsíci +2

      Godot is not a Unity replacement though, but its nice to see you did not give up.

  • @zongopbongo
    @zongopbongo Před 27 dny +4

    I appreciate how quickly you speak

  • @retoray
    @retoray Před 3 měsíci +2

    You made me understand signals! Didn’t think I would be able to get it ^^

    • @dev-worm
      @dev-worm  Před 3 měsíci +2

      so happy to hear!! thank you so much!! that means for than the world to me!!!

  • @edwardskeyara
    @edwardskeyara Před měsícem +1

    I want you to know i appreciate you talking fast, my brain runs fast and everyone else is super slow.

    • @dev-worm
      @dev-worm  Před měsícem +1

      i happy to hear that it was perfect for you!! thank you so much!! i am just so glad to help!

  • @N3verGiveUp
    @N3verGiveUp Před 3 měsíci +1

    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!!

    • @dev-worm
      @dev-worm  Před 2 měsíci

      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!

  • @YoKKJoni
    @YoKKJoni Před 4 měsíci +2

    very helpful and clear! i heard 4 minutes and i figured it out thank you

    • @dev-worm
      @dev-worm  Před 4 měsíci

      so happy to hear that! glad I could help! thanks! if you ever need anything then please let me know!

  • @Goldy131992
    @Goldy131992 Před 4 dny

    Very well explained as always, keep up the great work!

    • @dev-worm
      @dev-worm  Před 3 dny

      thank you so much!! it means the world!!

  • @ThunderPlayStudios
    @ThunderPlayStudios Před 7 dny

    it's my first time i've to slow down a video. :D btw great content

    • @dev-worm
      @dev-worm  Před 5 dny

      haha i’m sorry!! i hope it was still helpful!! thank you so much!! ❤️

  • @lmullins573
    @lmullins573 Před 23 dny

    Thank you man. This answered so many questions that I had. 🙏

  • @kristianlovealot
    @kristianlovealot Před 7 měsíci +4

    Thanks, Devworm :) Just what I need to get a better understanding of signals! Can't wait to watch this later!

    • @dev-worm
      @dev-worm  Před 7 měsíci +1

      thank you, I'm happy to hear that! I hope the video is able to help you understand signals a bit better!

  • @tuckerwoollard2613
    @tuckerwoollard2613 Před 3 měsíci +2

    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

  • @Trupen
    @Trupen Před 7 měsíci +2

    Thanks DevWorm

  • @PunCala
    @PunCala Před 7 měsíci +3

    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
      @dev-worm  Před 7 měsíci +4

      working on dash as we speak. thanks for the ideas ill look into them more!

    • @PunCala
      @PunCala Před 7 měsíci

      @@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

  • @ReddleyYT
    @ReddleyYT Před 7 měsíci +2

    Thank you, love your guides! You've become one of my favorite Godot channels!

    • @dev-worm
      @dev-worm  Před 7 měsíci +1

      so happy to hear that, glad im able to help.. if you ever need anything then please let me know!

  • @Juicein
    @Juicein Před 7 měsíci +2

    This is just what I needed! Thank you!🙏

  • @901oi2
    @901oi2 Před 25 dny

    man i love your videos

    • @dev-worm
      @dev-worm  Před 24 dny

      thanks bro!! it means the world!!

  • @Bk15729
    @Bk15729 Před 7 měsíci +2

    Thanks man. Needed this

    • @dev-worm
      @dev-worm  Před 7 měsíci

      so happy to hear that!

  • @electricelf-music
    @electricelf-music Před 4 měsíci

    You have no idea how long I have been searching for the answers that are well given in this video lol

    • @dev-worm
      @dev-worm  Před 4 měsíci +1

      so happy to hear!! thanks!

  • @hemapoojari630
    @hemapoojari630 Před 6 měsíci

    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

    • @dev-worm
      @dev-worm  Před 6 měsíci

      ah really?? must be.. that seems cool lol

  • @steve_rico
    @steve_rico Před měsícem

    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

  • @dasuper11
    @dasuper11 Před 6 měsíci +1

    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!

    • @dev-worm
      @dev-worm  Před 6 měsíci

      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.

  • @Moonajuana
    @Moonajuana Před 4 měsíci

    This is exactly what I needed, thank you so much!

    • @dev-worm
      @dev-worm  Před 4 měsíci

      happy to hear that! thank you!

  • @sergeym7213
    @sergeym7213 Před 5 měsíci +1

    Thanks for the tutorial, but what is the best way of connecting a signal emitted by another scene?

    • @USNTM2
      @USNTM2 Před 5 měsíci

      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.

  • @Garthritis
    @Garthritis Před měsícem

    Good stuff! Thanks

  • @tomod45
    @tomod45 Před 7 měsíci +1

    thanks for the tutorial!

  • @SheepUndefined
    @SheepUndefined Před 4 měsíci +2

    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.

    • @watcx
      @watcx Před měsícem +1

      He's just teaching horrible practices because he doesn't understand what he's doing himself.

  • @mincraft752
    @mincraft752 Před 4 měsíci +1

    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.

    • @dev-worm
      @dev-worm  Před 4 měsíci +1

      ill check it out, thanks!!

    • @mincraft752
      @mincraft752 Před 4 měsíci +1

      @@dev-worm Thanks!!!

  • @IronBen117
    @IronBen117 Před 3 měsíci

    super helpful, thanks!

    • @dev-worm
      @dev-worm  Před 3 měsíci

      thank you so much!!! glad it was helpful!!

  • @christo3058
    @christo3058 Před 2 měsíci

    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!

    • @dev-worm
      @dev-worm  Před 2 měsíci

      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!!

  • @Lambert06Pasquale06
    @Lambert06Pasquale06 Před 3 měsíci

    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.

  • @MochiRosu
    @MochiRosu Před 7 měsíci

    MCSquirmy the Legend!

    • @dev-worm
      @dev-worm  Před 7 měsíci

      @MochiRosu the Legend!

  • @WunderChilld
    @WunderChilld Před 7 měsíci

    Thanks for the videos brother, could you bring a video explaining how to enter/use some type of vehicle? whether horse, car, etc.

  • @ElementalTJ
    @ElementalTJ Před 7 měsíci

    You are the best!

    • @dev-worm
      @dev-worm  Před 7 měsíci +1

      thank you so much, youve just made my day! If you ever need any help with Godot then please let me know!

  • @AngelofD000M
    @AngelofD000M Před 4 měsíci

    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.

    • @dev-worm
      @dev-worm  Před 4 měsíci +1

      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

    • @AngelofD000M
      @AngelofD000M Před 4 měsíci

      @@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

  • @spasmodius8939
    @spasmodius8939 Před 13 dny

    thanks!

    • @dev-worm
      @dev-worm  Před 13 dny +1

      of course anytime! thank you!

  • @Pelipcahh
    @Pelipcahh Před 7 měsíci +1

    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.

  • @NamEch88
    @NamEch88 Před 5 měsíci

    Hello DevWorm!
    Your video is really helpful.
    Hope you can guide me on how to make a roguelike game like Brotato!

    • @dev-worm
      @dev-worm  Před 5 měsíci +1

      hey thank you so much! I'm actually working on a rogue like game tutorial series right now!

    • @NamEch88
      @NamEch88 Před 5 měsíci

      @@dev-worm Great! I look forward to it

  • @jitone1
    @jitone1 Před 4 měsíci

    I was trying to use the connect method to connect "open" signal to chests in multiply level scenes. Never go it to work right.

  • @fvhaudsilhvdfs
    @fvhaudsilhvdfs Před 7 měsíci +1

    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?)

    • @hadesiguess8516
      @hadesiguess8516 Před 7 měsíci +2

      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.

    • @dev-worm
      @dev-worm  Před 7 měsíci

      @@hadesiguess8516 that is a very good explanation of it

    • @fvhaudsilhvdfs
      @fvhaudsilhvdfs Před 7 měsíci

      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

    • @GrunkleSoos
      @GrunkleSoos Před 7 měsíci +1

      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.

  • @Frostbytedigital
    @Frostbytedigital Před 7 měsíci +2

    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.

    • @thesomeone2nd
      @thesomeone2nd Před 7 měsíci +4

      If you continue using godot there will be a time where you gonna need them

    • @Frostbytedigital
      @Frostbytedigital Před 7 měsíci +2

      @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.

    • @sataStrike
      @sataStrike Před 7 měsíci +2

      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.

    • @USNTM2
      @USNTM2 Před 7 měsíci +1

      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.

    • @bingusbingus7860
      @bingusbingus7860 Před 7 měsíci +1

      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.

  • @shoggoth
    @shoggoth Před 4 měsíci

    In example2, why not just have one signal and pass the colour as a parameter?

  • @Alikespan
    @Alikespan Před 4 měsíci

    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?

  • @Twisited
    @Twisited Před 7 měsíci

    thanks

  • @Epsio0
    @Epsio0 Před 4 měsíci

    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.

  • @Asilhan
    @Asilhan Před 3 měsíci

    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.

  • @rangergreen1935
    @rangergreen1935 Před 4 měsíci

    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

    • @dev-worm
      @dev-worm  Před 4 měsíci

      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!

  • @brisben88
    @brisben88 Před 2 měsíci

    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?

    • @dev-worm
      @dev-worm  Před 2 měsíci +1

      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!

    • @brisben88
      @brisben88 Před 2 měsíci

      @@dev-worm no worries, thanks for the clarification!

  • @MrGramno
    @MrGramno Před 7 měsíci

    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 ?

    • @InsanityForce
      @InsanityForce Před 7 měsíci +2

      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)

    • @tonnypedersen5915
      @tonnypedersen5915 Před 7 měsíci +2

      you could use a autoload singleton script and store you custom signals in that, that way dynamic loaded objects can communicate more easily.

  • @ongbui1796
    @ongbui1796 Před měsícem +1

    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?

  • @mkaks22gamerserise16
    @mkaks22gamerserise16 Před 2 měsíci

    bro there is one issue you teach so fast and i am a beginner i need some time

    • @dev-worm
      @dev-worm  Před 2 měsíci

      sorry bro! if there was anything you couldnt understand feel free to ask me! Im sorry it was all a little to quick!

  • @snugglyjeff214
    @snugglyjeff214 Před 5 měsíci +25

    talk slower!

    • @dev-worm
      @dev-worm  Před 5 měsíci +8

      okay! sorry, ill try!

    • @andrejjjj2008
      @andrejjjj2008 Před 4 měsíci +7

      No, don’t! ❤

    • @ObsydianX
      @ObsydianX Před 4 měsíci +5

      Playback 0.75 worked for me.

    • @biggusdickus6704
      @biggusdickus6704 Před 3 měsíci

      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.👍🏻

    • @ParacosmTV
      @ParacosmTV Před měsícem +2

      Definitely talk slower, wtf. Lol

  • @user-tm2vn5yj9r
    @user-tm2vn5yj9r Před 4 měsíci

    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.

    • @SheepUndefined
      @SheepUndefined Před 4 měsíci

      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.

  • @lazlohollyfeld3770
    @lazlohollyfeld3770 Před měsícem

    Decent Tutorial but damn slow down.

    • @dev-worm
      @dev-worm  Před měsícem

      i do apologize!! hope you were still able to get the information from it!

    • @lazlohollyfeld3770
      @lazlohollyfeld3770 Před měsícem

      @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.

  • @JuanDiaz-ks7xy
    @JuanDiaz-ks7xy Před 7 měsíci

    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

    • @chefaku
      @chefaku Před 4 měsíci

      when connecting the signal 3:23 click on advanced, and you can add arguments