List instance is always the same as the blueprint ?
Hello ! I've been debuging a script for my game for about 3-4 hours now... yeah... i waisted some time... the script is a pathfinding script and i am using lists to find possible ways of going to certain spots
here is my code, let me explain the problem
List<GameObject> listOfTheCurrentPathR = new List<GameObject>();
listOfTheCurrentPathR = listOfTheCurrentPath;
List<GameObject> listOfTheCurrentPathL = new List<GameObject>();
listOfTheCurrentPathL = listOfTheCurrentPath;
List<GameObject> listOfTheCurrentPathU = new List<GameObject>();
listOfTheCurrentPathU = listOfTheCurrentPath;
List<GameObject> listOfTheCurrentPathD = new List<GameObject>();
listOfTheCurrentPathD = listOfTheCurrentPath;
NewGoRight(x, y, movementLeft, listOfTheCurrentPathR);
NewGoLeft(x, y, movementLeft, listOfTheCurrentPathL);
NewGoUp(x, y, movementLeft, listOfTheCurrentPathU);
NewGoDown(x, y, movementLeft, listOfTheCurrentPathD);
i have a maximum movement of 4. When i launch the following code, the "listOfTheCurrentPath" has 3 GameObject in it. So all the other instances (listOfTheCurrentPathR,L,U,D) also have 3 GameObjects on them. First, the code will run the NewGoRight function and pass in a few parameters, but the one that i am focusing on is the listOfTheCurrentPathR parameter. In this function, i add a GameObject in this list. The problem is, for some reason, that when the GameObject is getting added on listOfTheCurrentPathR, it also is gettings added on every instance of the listOfTheCurrentPath, and listOfTheCurrentPath itself...
Is this a bug or am i doing something wrong ?
if i am please let me know :)
thank you !
Your answer
![](https://koobas.hobune.stream/wayback/20220612161058im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Using a specific function from a generic object. 0 Answers
Most efficient way to store information in an inspector dropdown menu? 0 Answers
Edit properties of certain list items,Changing properties of objects in a list (c#) 1 Answer
How To Find GameObject From List And Add To Player List 0 Answers
a list with a constructor class that also contains a list. 1 Answer