Audio null in unity

6.2k Views Asked by At

I am getting this weird error in unity when I am trying to run my (sad excuse for a) game. Here's the code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ARsound : MonoBehaviour
{

    public static AudioClip sound;
    static AudioSource audioSrc;


    void Start()
    {
        sound = Resources.Load<AudioClip>("AR SFX");
        audioSrc = GetComponent<AudioSource>();
    }

    public static void playSound()
    {
        audioSrc.PlayOneShot(sound);
    }


}

And the error is this:

PlayOneShot was played with a null audio clip

Even though that audio clip doesn't SEEM to be null. Here is some additional info:

Gun:Update() (at Assets/Scripts/Gun.cs:17)

Suggestions?

1

There are 1 best solutions below

0
Lucero On

Your call to Resources.Load returns null - this happens when the asset is not found (no exception).

See docs: https://docs.unity3d.com/ScriptReference/Resources.Load.html

So you need to make sure that the asset exists and that it can be loaded.