[Solved] Array is empty after Scene change..

Hello everyone,

I’m having trouble with an Array and I hope that somebody has an idea.

I’ve written an AudioControl Script to load Music into an Array.

public AudioClip[] mClips;

mClips = Resources.LoadAll<AudioClip> ("Audio/Music");

This works fine. In my MainMenu Scene and MainMenu.cs Script, I can play the music by script.
To check the array I made a Debug.Log.

foreach (AudioClip getTheClips in audioControl.mClips)
			Debug.Log ("MainMenu: " + getTheClips);

The result in my console is fine:

MainMenu: Soft1 (UnityEngine.AudioClip)

MainMenu: Stage1 (UnityEngine.AudioClip)

When I start the Game and switch the Scenes from MainMenu to Level_00 by SceneManger.LoadLevel the Array is used in my HealthController.cs

In the HealthController.cs I did the following to check the Array:

foreach(AudioClip theClips in audioControl.mClips)
			Debug.Log ("HealthController: " + theClips);

The result in console is just: HealthController:

No Error Message or Warning.

If I try:

public AudioClip levelMusic;

levelmusic = audioControl.mClips [1];
    Debug.Log = (levelmusic);

It returns just “Null” in Console.

public AudioControl audioControl;

//In Startfunction on both Scripts
audioControl = GetComponent<AudioControl> ();

Any help is appreciated.

Oh my, I tried so much…
Even with Script Execution Order.

I have no idea why, but changing this did it…

using UnityEngine;
using System.Collections;

public class AudioControl : MonoBehaviour {

public AudioClip[] mClips;

void Awake () // it was .. void Start()
	{
		mClips = Resources.LoadAll<AudioClip> ("Audio/Music");
}
}

Sure, there is way more code inside AudioControl.cs (just used the important code) but the Array isn’t empty in the Healthcontroller.cs anymore and Music works fine now after Scene change.

So, for now it’s Solved and hope it will work after the Build, but thank you both anyway for your ideas.
That gave me alot of thoughts for the future to keep in mind.

The Class and your initializing made me think , so i changed it from Start() to Awake();
I’m still new to Unity and C#, sorry for any inconvenience.