Problem understanding why the index is out of range using "datatree.PathExists(x)" methode

I cant understand why its throwing this exception.I understand the index is too high, for my tree, thats why I was checking it with the pathExists methode.

It has to be very simple, I am already spending too much time without understanding.
maybe someone could point it out for me. I would be really grateful.

Thanks and nice sunday evening! (19.0 KB)

private void RunScript(DataTree<Mesh> x, ref object A)
  var tBases = new DataTree<Mesh>();
  for (var i = 0; i < 151; i++)
    var path = new GH_Path(i);
    if (x.PathExists(path))
  A = tBases;
} (14.6 KB)

My guess is that PathExists expects a path, but you are giving an index, so it is a method that find for DataTree.Paths[i] and call PathExists(path) inside its body. In your case, ā€œiā€ is not a path, is a index of a path, and it can be out of range if your index is larger that the size of the collection. You are expecting to get new GH_Path(index) but you are getting DataTree.Paths[index].

oh yeah, thanks @Mahdiyar

Thanks for the explanation @Dani_Abalde!