Foldout loop structure problems

Greetings community !

I wrote code that draws tons of foldouts, depending on Data file information it reads.
Once user clicks and expands an foldout I draw even more controls that read even more data !
That works perfectly!

Problem comes in nature of my for loop and the way you check is an foldout expanded.

Let’s take a look, shall we ? :slight_smile:

for (var xy : int =0; xy <=2; xy++){

if (i >= l_Array.Length){
break;
}
		
			t_ListFoldouts[xy] = EditorGUILayout.Foldout(t_ListFoldouts[xy], l_Array*);*
  •  	if (t_ListFoldouts[xy]){*
    

l_Array = EditorGUILayout.TextField(“Sub Entry1 :”, l_Array*);
_ i++;*_

l_Array = EditorGUILayout.TextField(“Sub Entry 2”, l_Array*);
_ i++;*_

l_Array = EditorGUILayout.TextField(“Sub Entry 3”, l_Array*);
var tmpInt : int = parseInt(l_Array);
_ i++;*_

* for (var c = 0; c <= tmpInt-1; c++){*
l_Array = EditorGUILayout.TextField(“Sub Entry 4”, l_Array*);
_ i++;*_

l_Array = EditorGUILayout.TextField(“Sub Entry 5”, l_Array*);
_ i++;*_

* }*

* }*

}
So where is the problem ?
Anything bellow this IF statement :
if (t_ListFoldouts[xy]){
// Code
}
… logically only gets executed if bool is true. In order for bool to be true, user has to expand Foldout.
That doesn’t fit my needs as I write ID of entry in foldout and because of that code all foldouts are the same until user expands each one of them.
Solution to this is to expand all foldouts, but that’s not what I’m after, I want to keep ability to expand them by wish.
Is there some way around this ?
Regards.

Have you realized that when you collapse the foldout you’re no longer increasing your “i” value. To get the same i for the next foldout you would need to increase i manually by the same amount it would have been increased when the foldout was visible.

This indeed solved the issue.
In IF statement I added else and manually increased i in the same way I increase it when user expands foldout, thus resulting in correct data display.

I will wait for Bunny83 to convert his comment to answer so that I can tag it as answer.

Thanks :slight_smile: