how to add a node to a group in the editor using a tool script?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By serge059
:warning: Old Version Published before Godot 3 was released.

Hello,
I attached the script below to a Spatial node. When I run it (checking the ‘runScript’ box), it adds the node to ‘myGroup’ and prints ‘yes’. But nothing appears in the editor. How can I make it visible in the editor? Thanks for your help.

tool
extends Spatial

export(bool) var runScript = false setget onChecked

func _ready():
	pass

func onChecked(checked):
	if checked:
		runScript = false
		self.add_to_group('myGroup')
		if self.is_in_group('myGroup'):
			print('yes')
		else:
			print('no')

script reformatted for better reading

serge059 | 2018-01-30 18:50

OK, what did you actually want to happen? The program worked fine didn’t it. It became part of the group and that’s what you wanted right? Correct me if I am wrong.

SingingApple | 2018-02-18 02:52

Thank you for your answer. The node has been attached to the group but I cannot see it in the editor. What I would like to do is to save my scene with the node attached to the group. My final goal is to use this kind of tool in a large scene to automaticaly attach nodes to groups without doing this manualy and save the result. How would you do that?

serge059 | 2018-02-18 10:12

I see. But actually you cannot save the scene after attaching nodes to the groups in the script. What happens in the script happens within the game and will NOT result in any change in the editor. Hope that clarifies your misunderstanding.
As far as I know, you have to do this stuff manually. Correct me if I am wrong.

SingingApple | 2018-02-18 13:17

I already create nodes, add or remove child and rename nodes using a script tool. I only need to apply set_owner(get_tree().get_edited_scene_root()) to each created/modified node and everythings appears correctly in the editor and I can save the modified scene. But it does not work for groups and I don’t understand why. Do you have any idea or suggestion ?

serge059 | 2018-02-18 14:19

:bust_in_silhouette: Reply From: rossunger

If you’re talking about making it show up in the inspector, you need to call property_list_changed_notify() function for the inspector to update.