Deleting an Element from a List

Hi,
i have a “unit” class which has a Vector3-List attribute named “currPath”. I have a List of “units” and i want to remove the first element of the “currPath” attribute of every “unit” individualy(so i can only delete them under certain conditions). my problem is that everytime i call the RemoveAt(0)-Metod of the list it deletes the first element of every “unit” at once. so if i loop through every “unit” id deletet as many items from the “currPath” list as “units” i iterated through.

For example:
i start with:
Unit 1: currPath = [1,2,3,4]
Unit 2: currPath = [1,2,3,4]

and the code is something like

foreach (unit in units){
unit.currPath.RemoveAt(0)
}

my return is:
Unit 1: currPath = [3,4]
Unit 2: currPath = [3,4]
and not:
Unit 1: currPath = [2,3,4]
Unit 2: currPath = [2,3,4]

i dont refference currPath anywhere else.

Thanks for any help.

To me that simply looks like both unit1 and unit2 are referring to the same list object which is why they are identical and have two items removed.

Try to setup Unit1 to have “[1,2,3,4]” and Unit2 to have “[10,20,30,40]” as a test.

Actually they both reffered to the same currPath Element which I defined earlier for both. I use quite a lot computing power to get this List is there any way so that they reffer to different lists but i only have to execute the method to get the list once?

provide some code on how you create these lists

alternatively look into how to duplicate or copy a list value into a new one

I actually found a Solution. Thanks for the help!!