I am instancing 2 instances of the same scene, and want them to have different groups from one another, but the group is shared between them, is there any option to make independant groups for the different instances?
if not, any other recommendations for how to implement something similar are very welcome!
thanks in advance to anyone who wants to help!
that is what is happening
I probably should have specified a little more in the post, so I’ll do it here
the scene I am instancing is already instanced twice in the main scene. during the runtime I am instancing other packed scenes from the instanced scenes I have and adding them to the group. the group is premade but the nodes are instanced during the runtime and added during the runtime, before running the code the group is empty.
no, I am referring to Godot Groups, the ones you can manage in the “Node” tab that is in the top right of the screen.
I am asking if there is a way for an instanced scene to also have sort of an “instanced group” so that when a different instance of the scene adds children to the group, it is to a different independant group of its own and not to a shared group between all instances of the scene.
Sure, but I don’t see where you think it would be a problem? You could for example add the children to an “instance group” that uses the group name of the parent instance, something like str(get_parent()) for the group name?
I couldn’t find a way to make a group during runtime, only while in the editor through the Groups tab
If there is one, can you send it?
You do not need to explicitly create a group before assigning it to a node. Group names on a node behave more like tags, in that they can be freely added and removed. node.add_to_group("etc") will work as you’d expect regardless of whether you have created a group named "etc" in the editor.
I believe get_tree only gets nodes that are currently in the scene tree, so when you get nodes in the group it’s only finding nodes that exist in the tree, but you don’t add the newCard node as a child in the scene tree until later in the function. I think that if you moved your add_child(newCard) call to before your get_tree().get_nodes_in_group(group) call then it would probably work as expected.
If that doesn’t do it, can you explain more specifically what you want to happen and what is happening instead?
You need to add it to the SceneTree before being able to get the nodes in a group. I linked the documentation in my post but I’ll c&p here:
Adds the node to a group. Groups are helpers to name and organize a subset of nodes, for example “enemies” or “collectables”. A node can be in any number of groups. Nodes can be assigned a group at any time, but will not be added until they are inside the scene tree (see is_inside_tree). See notes in the description, and the group methods in SceneTree.