Hey, I’ve got this code initialize it but after initialization (in the class Start()) the 'new’s disappear later when I try to use the newly initialized structures I get array index out of bounds…
public float[] raceHumanDNA =
{
/* Height */ 0.500f, /* Head Size*/ 0.500f, /* Neck Size */ 0.500f,
/* Arm Length */ 0.500f, /* Hand Size */ 0.500f, /* Foot Size */ 0.500f,
/* Bandy Legs */ 0.500f, /* Upper Muscle */ 0.500f, /* Lower Muscle */ 0.500f,
/* Upper Weight */ 0.500f, /* Lower Weight */ 0.500f, /* Leg Size */ 0.500f,
/* Ear Size */ 0.500f, /* Ear Height */ 0.500f, /* Ear Angle */ 0.500f,
/* Nose Size */ 0.500f, /* Nose Curve */ 0.500f, /* Nose Breadth */ 0.500f,
/* Nose Slope */ 0.500f, /* Nose Height */ 0.500f, /* Nose Sharp */ 0.500f,
/* Nose Flat */ 0.500f, /* Chin Size */ 0.500f, /* Chin Sharp */ 0.500f,
/* Chin Height */ 0.500f, /* Jaw Jut */ 0.500f, /* Jaw Size */ 0.500f,
/* Jaw Height */ 0.500f, /* Cheek Size */ 0.500f, /* Cheek Height */ 0.500f,
/* Cheek Breadth */ 0.500f, /* Cheek Drawn */ 0.500f, /* Forehead Size */ 0.500f,
/* Forehead Depth */ 0.500f, /* Lips */ 0.500f, /* Mouth */ 0.500f,
/* Chest Size */ 0.500f, /* Buttock Size */ 0.500f, /* Arm Width */ 0.500f,
/* Forearm Length */ 0.500f, /* Forearm Width */ 0.500f, /* Belly Size */ 0.500f,
/* Waist Size */ 0.500f, /* Head Breadth */ 0.500f, /* Eye Size */ 0.500f,
/* Eye Angle */ 0.500f, /* Hair */ 0.500f, /* Hair Color */ 0.500f,
/* Eye Color */ 0.500f, /* Skin Color */ 0.500f
}; // Human
public struct bodyStruct
{
public string[] part; // morphable body part
public float[] dna; // scale for the body part
}// bodyStruct
public bodyStruct[] iBody = new bodyStruct[31];
void Start()
{
for (int i = 0; i < 31; i++)
{
iBody[i].part = new string[50];
iBody[i].dna = new float[50];
}// for
initializeAvatar(0);
return;
}// Start
public void initializeAvatar(int idx)
{
switch (idx)
{
case (0):
for (int i = 0; i < 50; i++)
{
Debug.LogError(" i = "+i+" idx = "+idx);
iBody[idx].dna[i] = raceHumanDNA[i];
}// for
break;
case (1):
for (int i = 0; i < 50; i++)
{
iBody[idx].dna[i] = raceElfDNA[i];
}// for
break;
default:
break;
}// switch
return;
}// initializeAvatar
The index out of bounds happenes the line after the Debug.Log…
e.g. The debug print shows both I idx to be 0 like I expect for the for loop with the ‘new’: those inits have disappeared. Is this some C# oddity or something peculiar to Unity Start()?
IndexOutOfRangeException: Array index is out of range.
UMACustomization.initializeAvatar (Int32 idx) (at Assets/UMA/UMA_Project/Scripts/UMACustomization.cs:720)
UMACustomization.Start () (at Assets/UMA/UMA_Project/Scripts/UMACustomization.cs:411)
Is my public float[ ] raceHumanDNA = … legal in C#?