Okay, basic thing here but I'm confused.....probably a bad day . This is the error I'm getting - On line 24. I don't see how it's trying to find something outside of the array. What am I missing.....? IndexOutOfRangeException: Array index is out of range. FFT_Analyser.Update () (at Assets/FFT_Analyser.cs:24) Code (csharp): public class FFT_Analyser : MonoBehaviour { public GameObject prefab; public int numberOfObjects = 20; public float radius = 5f; public GameObject[] bars; void Start() { for (int i = 0; i < numberOfObjects; i++) { float angle = i * Mathf.PI * 2 / numberOfObjects; Vector3 pos = new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)) * radius; Instantiate(prefab, pos, Quaternion.identity); } bars = GameObject.FindGameObjectsWithTag ("Bars"); } // Update is called once per frame void Update () { float[] Spectrum_Data = AudioListener.GetSpectrumData (1024, 0, FFTWindow.Hamming); for(int i = 0; i < numberOfObjects; i++){ Vector3 previousScale = bars[i].transform.localScale; previousScale.y = Spectrum_Data[i] * 40; bars[i].transform.localScale = previousScale; } } Best, Hawx PS. Yup I know it's not an FFT analyser.....well not yet.
Don't use a seperate int variable for the condition in the loop when iterating a collection. Use bars.Length instead of numberOfObjects and you won't run out of range.
looks like you're working on the assumption that the instantiated objects are tagged "Bars"? if that is the case it would appear that none of them are? it would probably make much more sense to add the instantiated objects to the array as they are created rather than using a find function.