- Home /
Passed variable clears in other component
Hello. I have strange problem. I pass variable "pointsList" to my other component and then I clear that "pointList" variable.
selectedObject.GetComponent(baseScript).setPath(pointsList);
pointsList.Clear();
I use that "pointList" variable like so:
function setPath(p : Array){
path = p;
c = 0;
moves = true;
}
Strangest thing is that when I clear my "pointsList" variable, it instantly clears "path" variable in that "selectedObject" component script. Any ideas why they are synchronized between each other?
Answer by tanoshimi · Jan 11, 2015 at 12:57 PM
Arrays (like all objects) are reference types - you're not passing the actual pointsList array to your setPath method, but merely a reference to where the data is stored in memory. Modifying the contents of that data will affect the "original" (i.e. only) copy.
Arrays (like all objects) are reference types
Are you sure you meant this? Objects made from Structs are not reference, but value types.
Your answer
![](https://koobas.hobune.stream/wayback/20220613180052im_/https://answers.unity.com/themes/thub/images/avi.jpg)