- Home /
MissingComponentException: no AudioClip even if i add it
so i was trying to use the beat detector by allanpichardo:
https://github.com/allanpichardo/Unity-Beat-Detection
I wanted to understand what the program was doing, so i didnt simply copy-paste everything. I typed everything myself, and came across something with an audio Object. The following lines will show you what he wrote and what i had to write instead ( i guess ):
AudioProcessor, line 81:
Him: samplingRate = audio.clip.frequency;
Me: samplingRate = GetComponent<AudioClip>().frequency;
AudioProcessor, line 122:
Him: if (audio.isPlaying) ...
Me: if (GetComponent<AudioSource>().isPlaying) ...
AudioProcessor, line 125:
Him: audio.GetSpectrumData(spectrum, 0, FFTWindow.BlackmanHarris);
Me: GetComponent<AudioSource>().GetSpectrumData(spectrum, 0, FFTWindow.BlackmanHarris);
I thought this must be the new way to write it ( had the same problem with a tutorial on the internet few weeks ago with "rigidbody", untill i read you have to use GetComponent() now ). It makes sense to me. So i added a AudioSource to my Main Camera, draged and droped my audiofile into the "AudioClip"-field and added the "Example"-script to an Object.
Running the program throws 2 different Exceptions. Iam going to focus in the first one. The second one is probably caused by the first one, so iam not taking this any further.
MissingComponentException: There is no 'AudioClip' attached to the "Main Camera" game object, but a script is trying to access it.
Why cant the program find my AudioClip and how do i fix this issue?
Thanks for the effort,
replayleif
I guess the problem is in
samplingRate = GetComponent<AudioClip>().frequency;
The $$anonymous$$ain Camera has no AudioClip component. So it has to be something like
samplingRate = GetComponent<AudioSource>().clip.frequency;
Answer by sankalp22 · Nov 30, 2015 at 06:35 PM
Try with youraudioSource.clip to get audio clip.
Thanks.
Your answer
Follow this Question
Related Questions
AudioSource and AudioClip. Stop and play drops an error. 1 Answer
Help with IEnumerator and if sound is playing 2 Answers
OnTriggerExit stop audio 1 Answer
Instanced Prefabs: Audio clip array out of range 1 Answer
Multiple audiosources 1 Answer