Is It possible to preload instances into a certain group?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By StsDevSquad

I have a group in my main scene called minimap_objects, and objects that are in that group show up on my mini map. If I try to preload the scene in code with a spawner it spawns the object , but not in the group, but if I drag the tscn file to my main file it shows up in the group. Any ideas?

:bust_in_silhouette: Reply From: sash-rc

First of all (pre)loading does not produce a Node, instance() does.
Second, Groups are no more than simple string tags, so they are simply loaded, not “into group”.
Moreover, Groups are managed by SceneTree, so node has be added to a tree, for a Group feature to work.

You can always check which nodes in tree belongs to a certain group with

var myGroupNodes = get_tree().get_nodes_in_group ("minimap_objects")