I am adding an onClick listener to a button thats created at runtime at runtime using:
currentButton.GetComponent<Button>().onClick.AddListener(delegate {
summonGolem(Mod.golems*.golemName, wand);*
});
And i get an ArgumentOutOfRangeException at:
summonGolem(Mod.golems*.golemName, wand);*
_*Here is the full error http://pastebin.com/CZ1R4MLB*_
Please help!
1 Answer
1
Your value for i is incorrect & you are running off the end of the golems array.
Add in some debug code like this:
currentButton.GetComponent<Button>().onClick.AddListener(delegate { summon(i);});
void summon(int i)
{
Debug.Log("summon "+i);
Debug.Log("#Golems "+Mod.golems.length);
summonGolem(Mod.golems*.golem,wand);*
}
As your error is in the delegate its very hard to add debug code. This way its easier to add the debug code & find out why it went wrong.
Nobody will be able to help you without more information... Are you sure you add values to your Mod.golems array ? Have you check the value index ? (>= 0 but < Mod.golems*.Length)*
– Hellium^This. You are trying to access a position inside your array that lies outside that array's boundaries, which are between 0 and it's Length -1.
– ChernoIm using the same index in there as i am when accessing other data from the same array in a different method. And if i hardcode the value it works just fine.
– drok0920