- Home /
Indexing lists based on positions
Hello, im having a problem where i need to be able to store objects in an array based on their position, that way i can retrieve them from the array, if i know the position of the object.
I decided to just use a List>> type structure but then realized that you cant use a negative value as an index, therefore i cant store anything that has a negative position, so i need a different way of doing this.
Any suggestions?
Answer by SirGive · Aug 04, 2012 at 05:23 AM
http://msdn.microsoft.com/en-us/library/x0b5b5bc
Try List.Find()
Might not be supported by Unity though.
Answer by nickolouse · Aug 04, 2012 at 05:29 AM
If you know the largest possible negative value you could offset the values. So that way your lowest possible value would be 0. For example your values can be between -256 and 256 you could just add 256 to all values to find the index. If you do not know the range than this will not work. I suppose you could also use two lists one as the absolute value of the negatives and one as the positive values. Hope this makes sense.
Hmm that would be a good idea, but it isnt limited to a size really, seeing as how its chunks which can be made during runtime for ever how far is needed :l
Your answer
![](https://koobas.hobune.stream/wayback/20220613075146im_/https://answers.unity.com/themes/thub/images/avi.jpg)