- Home /
SIngleton Array problem (Array Index out of Range, but index = 0)
So my problem is within my referenceManager that handles common GameObject references. These are all singletons. my singleton stuff is done with this:
private static referenceManager m_Instance = null;
public static referenceManager Get()
{
if (m_Instance == null)
m_Instance = (referenceManager)FindObjectOfType(typeof(referenceManager));
return m_Instance;
}
the length of my array is set in editor, i fill it with the following code in void Awake:
for (int c = 0; c < Collectibles.Length; c++)
{
Collectibles[c] = GameObject.Find("Collectible" + (c+1));
}
This all seems to work, because in editor it is all filled in. When i now try to reference the array in different scripts with smth like this...:
Debug.Log(referenceManager.Get().Collectibles[0].name);
...i get the followeing error message:
Since i also had some other issues with the array i think i do smth wrong, but i dont know what. Ive searched all over google for explanantion, but couldnt find someone with my exact problem. Any help is very appreciated.IndexOutOfRangeException: Array index is out of range. collectibleManager.Start () (at Assets/scripts/paths/collectibleManager.cs:32)
where did you call this code?
Debug.Log(reference$$anonymous$$anager.Get().Collectibles[0].name);
Answer by TherealCatman · Oct 05, 2018 at 05:21 PM
I tried out gameObjects Lists instead and now it works perfect.
Your answer
![](https://koobas.hobune.stream/wayback/20220612175739im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
List of scripts? 2 Answers
Add two radius on the same shader 1 Answer
error CS0029: Cannot implicitly convert type `UnityEngine.GameObject' to `int' 1 Answer
Can´t instantiate objects in list correctly 1 Answer
Interstitial ads is not showing 0 Answers