Something missing in my editor? chapter 7 - sounds

Hello,
I’m just starting to learn about unity,
in chapter 7, maybe I’ve wrong configured in my editor or maybe I’ve found a mistake in the book.
in SoundManager.cs when searching for available AudioSources, in the if statement if don’t modify the condition to if(source.clip != null), it’s giving me an error in the console:

NullReferenceException: Object reference not set to an instance of an object
SoundManager.PlayOneShot (UnityEngine.AudioClip clip) (at Assets/Scripts/SoundManager.cs:55)
Alien.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/Alien.cs:34)

as I’d revised and rewritted the code several times from sources downloaded, I have the feeling that something in my editor is missing,

could you help me please??

It’s hard to say without looking at your code, but it looks like you are missing an audio source on the sound manager. Typically, whenever you get a null reference exception, that means unity is trying to access a component or object that isn’t there.

Or it could be mean that you’ve attached the manager script to another gameobject. My suggestion is to compare your current project with the final project for the chapter. That way, you’ll be able to determine if an object is missing something.

Thanks!! that’s it…
I only had one Audio Source in SoundManager, the one copied from MainCamera but the blank Audio source was missing, once I’d added it, SoundManager works perfectly
thanks in advance,
regards,

1 Like

Awesome! I’m glad to hear you were able to work through it. Cheers!

This topic was automatically closed after 166 days. New replies are no longer allowed.