I'm beginner in c#, and I'm trying to get a list of values but I get a null object reference.
I have a dictionary
var stripes = new Dictionary<int, List<Transform>>(); and I'm trying to get the list of transforms
foreach (var stripe in stripes) { List<Transform> transforms = stripe.Value; foreach (var treeTransform in transforms) { float distance = DistanceToCameraPlane(treeTransform.position); TreeObject treeObject = new TreeObject(); treeObject.distance = distance; treeObject.tree = treeTransform; sortedTrees.Add(treeObject); } } However I get a null object references in treeTransform.position
nullelements inside your transforms collection. Since you get theNullReferenceExceptionon thetreeTransform.positionline, which meanstreeTransformis null somehow