Declaring Array, HELP.
Hello! I have a bool array with variable size X, called expand. I will be used on my Custom Editor, for X foldouts.
bool[] expand;
int i = 0;
foreach (string[] x in reference.Answers){
expand[i] = EditorGUILayout.Foldout(expand[i], reference.Lines[i]);
i++;
}
Visual Studio says that expand[i] is not assigned, thus cannot be used. How can I a defalt value for the array? Have a nice day!
$$anonymous$$ight aswel write it like this:
bool[] expand = new bool[reference.Answers.Count];
for (int i=0; i < reference.Answers.Count; i++)
{
expand[i] = EditorGUILayout.Foldout(expand[i], reference.Lines[i]);
}
Use reference.Answers.Count if its a list else use reference.Answers.Length if its an array.
Answer by Kaskorian · Jul 15, 2017 at 03:32 PM
your Array has no size.
this will solve it:
private bool[] expand = new bool[your size];
and be careful. The Array goes from 0 to the size - 1.
Your answer
![](https://koobas.hobune.stream/wayback/20220612130336im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
random spawn enemy problem 0 Answers
How to disable raycast/groundchecker on OnTriggerEnter? 0 Answers
Timer wont work 0 Answers
Getting weird error message!?!?!? 1 Answer
How do I find the direction I'm going for my blend tree? 0 Answers