B
B
Bruh_Bruh2021-06-08 20:49:26
Unity
Bruh_Bruh, 2021-06-08 20:49:26

Why does List.Count return the wrong number of elements?

Positions.Add(position);
Debug.Log(Positions.Count);
for (int i = 0; i < Positions.Count; i++)
{
Debug.Log(Positions.Count);
Debug.Log(Positions[i]);
}


So the method is called twice => there are two elements in the sheet.
However, the debugs of Positions.Count show a value of 1.
And the most interesting thing is that the debug of all elements of the sheet shows two different vectors, which they should be.
And what happens? If count = 1, and the console shows two vectors, then this means that in the for loop the condition 1 < 1 is true ??? Is this possible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Kachan, 2021-06-09
@MANAB

So the method is called twice => there are two elements in the sheet.
not true if you have Positions defined globally and not locally. If defined locally, there will be 1 element each time.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question