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
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)
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.
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')
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. :)
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
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)
@@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 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, ....).
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.
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.
for me these are the perfect godot 4 quick-sheet videos. keep it up and never stop.
Thank you!
As always your channel helping me with complex problems and using easy to understand solutions!😊
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?
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)
You are very welcome! 😊😊
clean explanation of what groups are, i saw the tab and didnt know what it was, thank you
You are welcome. Thank you!
dear god they finally figured out object oriented programming
CLEAN 😍
Thank you 😍😁
Nice editing and graphics!
Thank you!
Great animations
Thank you : )
Thanks, subscribed.
Thank you!
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.
No, you can have nodes of different types within a group.
how do i do it that an object scans if the body it touches is in a specific group?
nice tutorial though.
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')
@@JumboGamedev thx
You could also use if body.is_in_group(“Desired Group”):
what if a node you want to put in a group is in a different scene?
It should work fine. You can add nodes from different scenes to the same group.
Thanks for the great video. Can't any Node becomes a parent and in this way it's like a group?
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.
:)
you can have nodes that are in COMPLETELY different places in the scene tree but still have them in the same group
@@JumboGamedev Yeah, sorry, stupid question I forgot about the native Group feature in Godot... Thanks... the videos are amazing.
@@HoutarouOrekiOsuYeah I forgot about the Godot Group Feature... I was thinking on something else... Thanks
@@ekagaurangadas Thank you! you are very welcome : )
Is this like the tag system of unity?
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
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
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)
@@JumboGamedev Thank you, I'll try that later
@@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?
Ok, nevermind, i discovered I can use get_tree().set_group() and pass the variable. Anyways, thank you so much for the help
@@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, ....).
Do you think groups are as fast as a "for" loop for a parent's children?
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.
@@JumboGamedev Thank you for your answers :)
@@longuemire748 You are very welcome :)
I don't understand the difference between a group and a inheretation
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.