Search Unity

Bug I cannot assign AudioClips to scripts that have an AudioClip component

Discussion in 'Editor & General Support' started by emilylena, Feb 24, 2023.

  1. emilylena

    emilylena

    Joined:
    Jan 18, 2018
    Posts:
    10
    I don't know why, but for some reason in Unity 2020.3.19f1 (I know I know, I probably should update but I first want to see if this issue can be fixed) I cannot assign AudioClips through script. If I add a public AudioClip clip; to my script, and then in the inspector drag any audiofile to it, it just seems like nothing happened. If I click the little dot, same issue.

    If I add an AudioSource to my script, and then try clip = source.clip; I get an error like this:
    upload_2023-2-24_18-56-3.png

    In short, what the hecc is going on with my Unity? Why is it going bonkers saying it cannot convert AudioClip to AudioClip? I genuinely have never seen such a stupid error message lol

    Anyways, I'm sure I am doing something wrong but I genuinely cannot find what and having tried for an hour to find anything via Google and it just comes up short, no one seems to have this issue. Everyone seems to just be able to drag audiofiles to a script that has an AudioClip component on them

    Thanks in advance for any reply, I appreciate it, this'll help me so I can continue.
     
  2. emilylena

    emilylena

    Joined:
    Jan 18, 2018
    Posts:
    10
    Never mind, I finally figured out the issue
    And it turns out, it was just me having made a dumb mistake :')

    I had called the script AudioClip without thinking, so it obviously overrides the standard behaviour that Unity normally has when calling an AudioClip. Just a dumb mistake haha
     
    chemicalcrux likes this.
  3. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    720
    Ah, yep! I just did that to myself this morning...

    It's a very easy mistake to make, especially as you add more and more non-namespaced classes to your project (or bring those namespaces in with a
    using
    statement. It can cause weird problems in random places as your definition suddenly gets into a fight with the existing one.