Pick-up SFX only playing in one ear

Hello. I’m working on a game & when I collect the pick-up, the first one sounds fine. However, when I collect the other instances of the prefab, the audio only plays in the left ear. Here is my code:

[SerializeField] AudioClip pickupSFX;

    void OnTriggerEnter2D(Collider2D other) {

        if (other.tag == "Player") {

            AudioSource.PlayClipAtPoint(pickupSFX, Camera.main.transform.position);

            Destroy(gameObject);

            ScoreManager.instance.AddPoint();

        }    

    }

Any help would be greatly appreciated.

Hi Zunaim,

You are in the Tile Vania section, aren’t you?

It’s just a guess but maybe the problem is caused by PlayClipAtPoint. Since the camera gets moved by the cinemachine, it might be that the camera is “suddenly” somewhere else when the sound gets played.

Try to not move the player to the left or right when collecting the pick-up. If the clip sounds fine in that case, my assumption is very likely correct.

In that case, you will have to add an AudioSource component to a game object that does not get destroyed while the scene is active. In your script, you reference that AudioSource object and call the PlayOneShot method on it. In the AudioSource component, make sure the Spatial Blend is set to 2D.

Did this fix the issue?


See also:

1 Like

Hello Nina & thanks for the reply. The problem seems to persist even if I don’t move my player while collecting. The spatial blend is set to 2D. Is there another way of tackling this problem? Thanks.

Where is your AudioListener? Usually, it is assigned to the Main Camera game object. Maybe you could assign the AudioSource to that game object. You called PlayOneShot on the AudioSource, didn’t you?

If so, which version of Unity do you use? Maybe there is a bug.

The Audio Listener is assigned to the Main Camera. And regarding PlayOneShot, can you please link to an article which explains it & also, what does it has to do with PlayClipAtPoint? Much thanks.

PlayOneShot is a method of the AudioSource object.

PlayClipAtPoint caused undesired effects in your game. That’s why I suggested an alternative solution.

I’m using Unity version 2021.2.8f1

Have you already tested PlayOneShot?

Sorry for the late reply Nina. I haven’t been feeling well. As for the PlayOneShot, no audio is playing in editor mode. I’ve been facing issue of some audio not working in edit mode, but working when I export a build. So, I might try to build it and update you accordingly.

Is the sound muted in the game window? There is a button in the top horizontal menu bar of the game window.

No, the audio is not muted.

How did this work?

Unfortunately, it doesn’t work.

Could you please share more information on what you did and have in Unity? Screenshots of the Hierarchy and the Inspector of the concerning game objects could be helpful. Also share your relevant code, so I can see how you implemented the PlayOneShot part.

Hierarchy One


Inspector Two

The “Data” is the name of the collectible item (makes sense in the lore of the game) & I’ve provided you with the screenshots of the inspector. I’ll share the code in a separate reply.

Here’s the code:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class DataPickup : MonoBehaviour

{  

    [SerializeField] AudioClip pickupSFX;

    AudioSource audioSource;

    void Start() {

        audioSource = GetComponent<AudioSource>();

    }

    void OnTriggerEnter2D(Collider2D other) {

        if (other.tag == "Player") {

            audioSource.PlayOneShot(pickupSFX, 1.0f);

            Destroy(gameObject);

            ScoreManager.instance.AddPoint();

        }    

    }

}

Thank you. That was helpful.

The reason why you do not hear any sound is very likely this Destroy(gameObject);. The AudioSource is on the same game object, and destroyed AudioSources cannot play any sound. For testing purposes, you could comment the line with Destroy out. If you hear the sound, you found the reason why you were not able to hear anything.

However, it might be that you still encounter the same problem as in your initial post.

I suggested to attach the AudioSource component to the Main Camera and reference the AudioSource in your script (DataPickup). Have you already tried that? The rest of your code looks fine to me apart from audioSource = GetComponent<AudioSource>();.

Unfortunately, the problem still exists. I don’t get the part where you’re telling me to add an AudioSource component to the Main Camera. What should I put in the AudioClip field? And how should I reference the AudioSource component on the Camera in the Data Pickup script?

Just add the AudioSource component to the Main Camera. That’s the first and most important step. Remove the AudioSource component from the Data Pickup game object.

What should I put in the AudioClip field?

Nothing. You are passing on the clip with PlayOneShot. See this line in your code:
audioSource.PlayOneShot(pickupSFX, 1.0f);. That line is everything (apart from the AudioSource object) you need to play your sound.

And how should I reference the AudioSource component on the Camera in the Data Pickup script?

The same way you referenced the AudioClip object at the top of your code and in the Data Pickup component in the Inspector.

If you don’t know how to achieve that:

Use the [SerializeField] attribute in front of audioSource and assign the reference to the AudioSource object to your audioSource variable manually in the Unity Editor.

Unfortunately, with this approach, not only does the pickupSFX sound not play at all, the DataPickup object is not being destroyed once the player enters the trigger. Is there any problem with my prefab? I might try to create a new prefab & delete the old one & see how it works.

Privacy & Terms