How to change a variable value in script to affect all its instances?

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

I am using a speed variable in a enemy script.i want to change its speed when player collided with some area.enemy was instances from a enemy spawner node.
When I changed variable value it affect spawned enemy only…I want movespeed To affect all of my enemy.i am using a single script for all enemy

:bust_in_silhouette: Reply From: Wakatta

Add all those enemies to a group

var _ready():
    add_to_group("ENEMY")

Use sceneTree’s group call and object’s set property

get_tree().call_group("ENEMY", "set", "movespeed", 600)

Or add all enemy nodes as child of one node and loop through each node setting that value

for child in parent_node.get_children():
    child.movespeed = 600

Thanks. :smiling_face::smiling_face:

Nivasraj | 2021-07-25 18:26