Godot 4 | groups overview

Sdílet
Vložit
  • čas přidán 15. 07. 2024
  • The video covers the following:
    - what are groups in Godot.
    - 2 ways to add nodes to a group
    ~ UI
    ~ code
    - nodes in a scene instance
    becoming part of a group
    - using call_group
    #godot #gamedev #gameengine

Komentáře • 45

  • @xtreme-software
    @xtreme-software Před rokem +6

    for me these are the perfect godot 4 quick-sheet videos. keep it up and never stop.

  • @nionbluh
    @nionbluh Před rokem +2

    As always your channel helping me with complex problems and using easy to understand solutions!😊

    • @nionbluh
      @nionbluh Před rokem +1

      A question, in the parameter that asks for the string of a method as an argument, can I use a custom method? created by me?

    • @nionbluh
      @nionbluh Před rokem +1

      Never mind, I learned that that node that is in the group needs to have the method created in it or a method of the node itself and not a method that does not belong to it or that does not exist in that node, even so, thank you very much! I've been trying to solve some problems in my project for a while (I'm new to game development in general and especially in godot)

    • @JumboGamedev
      @JumboGamedev  Před rokem

      You are very welcome! 😊😊

  • @thinktanium9789
    @thinktanium9789 Před 9 měsíci

    clean explanation of what groups are, i saw the tab and didnt know what it was, thank you

  • @marktime.
    @marktime. Před 9 měsíci +1

    dear god they finally figured out object oriented programming

  • @cynerboy
    @cynerboy Před 9 měsíci +1

    CLEAN 😍

  • @compasscrafting1147
    @compasscrafting1147 Před 11 měsíci +2

    Nice editing and graphics!

  • @blendjams
    @blendjams Před 9 měsíci

    Great animations

  • @meraklmuskulpesent8313

    Thanks, subscribed.

  • @TheRealAfroRick
    @TheRealAfroRick Před 8 měsíci

    Very cool. I'm going to start putting stuff into groups for better organizing things. One question about groups is whether or not the nodes in the group have to be homogeneous.

    • @JumboGamedev
      @JumboGamedev  Před 8 měsíci +2

      No, you can have nodes of different types within a group.

  • @jussch5752
    @jussch5752 Před rokem +2

    how do i do it that an object scans if the body it touches is in a specific group?
    nice tutorial though.

    • @JumboGamedev
      @JumboGamedev  Před rokem +1

      One way to check if a node is in a specific group is to loop over the nodes in the group and compare them with the body/node you have. It will roughly be something like that:
      func isNodeInGroup(node, groupName):
      if get_tree().has_group(groupName): # check if there is a group with that name
      for groupNode in get_tree().get_nodes_in_group(groupName):
      if node == groupNode: # found the node
      # put code for node found here and make sure to return
      return
      # put code for node not found here
      else:
      # put code for group not found
      # to use it:
      isNodeInGroup(node, 'someGroup')

    • @jussch5752
      @jussch5752 Před rokem +1

      @@JumboGamedev thx

    • @nathanwinsor1757
      @nathanwinsor1757 Před 8 měsíci

      You could also use if body.is_in_group(“Desired Group”):

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

    what if a node you want to put in a group is in a different scene?

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

      It should work fine. You can add nodes from different scenes to the same group.

  • @ekagaurangadas
    @ekagaurangadas Před 10 měsíci +2

    Thanks for the great video. Can't any Node becomes a parent and in this way it's like a group?

    • @JumboGamedev
      @JumboGamedev  Před 10 měsíci +1

      I think so yes, making multiple nodes a child of a node is good for organization and can be thought of as a folder/group of nodes.
      However, using groups has more benefits:
      - You can add a node to multiple groups. As an example, say you have a node called `square_1`, you might want to add this node to a group called `shapes` and another group called `squares`. In this case, you can do what you want (eg. invoking a function) on all squares at once, including `square_1`. And you can do what you want on all shapes at once, including `square_1`.
      - Groups already provide utilities (eg. invoking functions on all nodes in the group `call_group` or sending notifications). If you make the nodes have a common parent to group them, you will have to manually loop over them and do what you want. Indeed, this gives you more control, but more work to do.
      :)

    • @HoutarouOrekiOsu
      @HoutarouOrekiOsu Před 10 měsíci

      you can have nodes that are in COMPLETELY different places in the scene tree but still have them in the same group

    • @ekagaurangadas
      @ekagaurangadas Před 10 měsíci

      @@JumboGamedev Yeah, sorry, stupid question I forgot about the native Group feature in Godot... Thanks... the videos are amazing.

    • @ekagaurangadas
      @ekagaurangadas Před 10 měsíci

      @@HoutarouOrekiOsuYeah I forgot about the Godot Group Feature... I was thinking on something else... Thanks

    • @JumboGamedev
      @JumboGamedev  Před 10 měsíci

      @@ekagaurangadas Thank you! you are very welcome : )

  • @blendjams
    @blendjams Před 9 měsíci

    Is this like the tag system of unity?

    • @JumboGamedev
      @JumboGamedev  Před 9 měsíci

      I haven't used unity for quite a long time now, so I am not entirely sure. But I think they are the same idea, yes. They both allow you to group/categorize objects.
      Also, Godot's documentation says: "Groups in Godot work like tags in other software."
      docs.godotengine.org/en/stable/tutorials/scripting/groups.html

  • @last7665
    @last7665 Před rokem

    Please help me, I'm using the function get_tree()call_group() and it isn't working, there's no error message it just isn't working

    • @JumboGamedev
      @JumboGamedev  Před rokem +1

      I think this maybe because the nodes are not
      in the group you are specifying.
      - Maybe check if the group is actually loaded and contains nodes.
      Try something like that in the line just before call_group:
      ~ print(get_tree().has_group("...")) # replace '...' with your group name
      ~ print(get_tree().get_nodes_in_group("..."))
      - make sure that the group name passed to call_group()
      is identical to the group name you defined.
      ('abc' and 'ABC' are not the same groups, it has to
      be identical in lower/upper cases)

    • @last7665
      @last7665 Před rokem

      @@JumboGamedev Thank you, I'll try that later

    • @last7665
      @last7665 Před rokem

      @@JumboGamedev Ok, so here's what happens: I checked and all my nodes on the group are there, i've verified with both methods, and I'm now able to call all the nodes on the group. The problem is that I can't pass arguments for the methods, like "print". I can only do this when I have the specif method declared on the node, and to do that I need to add a lot of scripts. Is there some way to do that without using the script, or some way to make one script affect other nodes that aren't child?

    • @last7665
      @last7665 Před rokem

      Ok, nevermind, i discovered I can use get_tree().set_group() and pass the variable. Anyways, thank you so much for the help

    • @JumboGamedev
      @JumboGamedev  Před rokem +1

      ​@@last7665 So sorry, somehow I forgot to reply. You can pass the arguments to the method through call_group directly. It takes this form: call_group("group", "method", arg1, arg2, arg3, ....).

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

    Do you think groups are as fast as a "for" loop for a parent's children?

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

      You can run some performance tests by measuring the time it takes each method to iterate over the nodes. This will give you the best answer. It is hard to take a guess without checking the source code to know the underlying data structure used for groups or direct children. However, I think there could be a slight advantage for the "for" loop method, since you are iterating over the children of a given node. I also think that iterating over a group may be an advantage in the case were the nodes are scattered around the scene tree. In practice, I think the performance difference between these two approaches is likely negligible.

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

      @@JumboGamedev Thank you for your answers :)

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

      @@longuemire748 You are very welcome :)

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

    I don't understand the difference between a group and a inheretation

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

      A group is a way to organize nodes in your scene. For example, if you have multiple Area2D nodes that represent coins in your scene; you may want to add all of these nodes into a group. This is useful in case you want to do an operation that involves all of these nodes (eg. hiding all of the coins in your scene).
      Inheritance is programming concept that allows a new class to inherit attributes from an existing class. Godot uses this concept extensively. For example, Sprite2D inherits Node2D. This means that a node of type Sprite2D contains all the attributes that a node of type Node2D has.