Strange behaviour Array in OnStart()

Hi, i have strange behaviour, i make script for playing audio, i’m using eventmanager but i dont show them in code below(too long).

using UnityEngine;
using System.Collections;



[RequireComponent(typeof(AudioSource))]
public class EventListener : MonoBehaviour {
    public AudioSource s1;
    public AudioSource s2;
    public AudioSource s3;
    public AudioSource s4;
    public AudioSource s5;
    public AudioSource[] efek;
	// Use this for initialization
    void OnStart()
    {
         efek = GetComponents<AudioSource>();
         s1 = efek[0];
         s2 = efek[1];
         s3 = efek[2];
         s4 = efek[3];
         s5 = efek[4];
        
    }

void onSoundUp(int a)
    {

        Debug.Log(efek.Length);//return 0
        s1.Play();// worked
efek[0].Play(); // error
    }
 }

Anyone can explain this phenomenon? Besause if I have more AudioSource, without array it will be annoying :frowning:

Sure, that’s simple :wink:

There is no “OnStart” callback.

The variables s1 to s5 are probably set in the inspector, that’s why they work.

“OnStart” is never called. The actual callbacks name is “Start”.