Updated all node instances but need only one

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

Hi community!

I don’t understand something.
I create one parent class Tower and extend in difference towers, for example Archer.gd (linked to Archer. tscn):

extends Tower


extends Node2D

class_name Tower

var build: bool = false
var type: String
var tower_level: int = 0
var range_radius: AnimatedSprite
var collision: CollisionShape2D

func _ready():
	if build: 
		collision = get_node("Range/Collision")
		range_radius = get_node("Range/RangeRadius")

func _init_tower():
	var range = _get_tower_level_data(tower_level, "range") ##return int 
	range_radius.set_scale(Vector2(range, range)) 

func _update_level():
	tower_level += 1

And I instance him in main script:

func _build_tower(type: String, position: Vector2):
	var tower = load("res://Scenes/Towers/Archer.tscn").instance()
	tower.build = true
	tower.type = type
	tower.position = Vector2(position.x + 64, position.y + 64)
	tower.scale = 0.75 * tower.scale
	towers_node.add_child(tower, true)

I call update tower → tower._update_level(), the do update all towers, and not specific tower. What I don’t understand? I need update this only for specific tower.
It will update collision (CollisionShape2D) for all tower, but range_radius (AnimatedSprite) only for specific tower.


It’s likely because your CollisionShape2D is sharing a resource between all instances. Try making it unique

godot_dev_ | 2023-04-24 23:07

:bust_in_silhouette: Reply From: azusdex

Thanks godot_dev_ for you answer is work!

Left click in Shape in inspector → Resources → Local To Scene.