Changing attribute to one instantiated node change it for all the others

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

Hello,
I have a constant attribute on my script which preload a scene

const NODE_POINT = preload("res://Scenes/3D/Point.tscn")

Then I use it to instantiate nodes like this

for _i in range(11):
    var node = NODE_POINT.instance()
	$Line3D.add_child(node)
	points.append(node)
	var snode = NODE_POINT.instance()
	$StraightLine3D.add_child(snode)
	straightPoints.append(snode)

But the problem is everytime i want to change one attribute of any one of those instances it change it for every instance, even this line

straightPoints[0].changeIsStraight(true)

How can I separate behaviour of every instance ?

:bust_in_silhouette: Reply From: Inces

What behaviour do You want them to have ? You are instatiating them all under one loop, so they will share everything below for keyword, however You can use “_i” as iteration index to recognize each individual instance and order it accordingly. For example place each instance along the path with distance multiplied by _i, or make each node move left or right depending on division rest (modulo) of _i by 2, and so on. Tell me more about what do You want instances to do and I will try to design code.

Actually I fixed the problem, I had ressources in my scene that i needed to make local to scene. Once i did that my code worked as I expected. However thank you for your answer !

Endolo | 2021-11-07 01:00

@Endolo, how do you make resources local to the scene?

fccoelho | 2022-07-20 16:07

:bust_in_silhouette: Reply From: Endolo

Actually I just had to make all of my ressources local to scene in the one I instanciate.