Floating Objects Despite Gravity Used and No Colliders Preventing Fall,Floating Object in Unity Despite Collision Underneath Removed

At the moment I’m creating a breakout style game where the blocks are removed when hit by a ball, the blocks stack on top of each other and use Unity’s built in gravity with constraints on everything but the y-position to function. All was fine with the game as I was destroying the objects as they were hit, however once I wanted to add audio to the collision this was no longer viable as the object had to be around long enough to play the sound, but disappear on contact, this was my solution.
160973-codesnippet.png

For the most part this is functional code, most blocks fall as you’d expect though every time I run the game, 2-4 blocks remain in the air, even once the object underneath has been destroyed as can be seen here:

There is definitely no gameobject underneath them, no collision box that isn’t the table which uses an exact box collider, as does the block itself. Editing the rigidbody or collider in any way causes it to update in some way and realise there’s no collision underneath it, proceeding to fall as expected. From changing the detection mode to turning gravity on and off again it seems as if the object just forgets its supposed to check if there’s something underneath it to fall.

If anyone has any ideas or alternate solutions I’ll take anything at this point, thanks in advance!

I believe this is an architecture problem you are seeing here, and you may wish to read about the Single-responsibility principle.

I would rather make a SoundManager that is always alive and has the responsibility to play sounds, that way you can kill, destroy or pool your objects.

Something like this:

using UnityEngine;

[RequireComponent(typeof(AudioSource))]
public class SoundManager : MonoBehaviour
{
    public static SoundManager instance;

    [HideInInspector]
    public AudioClip exampleSound, secondExampleSound; // stored in Resources/Sounds

    AudioSource _audioSource;

    private void Awake()
    {
        if (instance != null && instance != this)
        {
            Destroy(this.gameObject);
            return;
        }
        else
        {
            instance = this;
        }

        _audioSource = GetComponent<AudioSource>();
    }

    void Start()
    {
        exampleSound = Resources.Load<AudioClip>("Sounds/" + "exampleName");
        secondExampleSound = Resources.Load<AudioClip>("Sounds/" + "secondExampleName");
    }

    /// <summary>
    /// Plays the sound with a matching name to the first parameter from the
    /// audioSource passed in as the second parameter
    /// </summary>
    /// <param name="clip">Name of the clip to be played (camelCase format)</param>
    /// <param name="src">Audiosource to play this sound from</param>
    public void PlaySound(string clip, AudioSource src)
    {
        switch (clip)
        {
            case "exampleName":
                src.PlayOneShot(exampleSound);
                break;

            case "secondExampleName":
                src.PlayOneShot(secondExampleSound);
                break;
        }
    }

    public void Play(string s)
    {
        if (!_audioSource.isPlaying)
        {
            PlaySound(s, _audioSource);
        }
    }
}

Then you can simply call it like so:

// play from specific audio source
SoundManager.instance.PlaySound("exampleSound", myAudioSource);

// or

// play from general audio source
SoundManager.instance.Play("exampleSound");

I hope this helps.

P.s, remember to not post code in screenshots but rather press the 101/010 button and paste your code, that way it is easier for people trying to help you to debug your code.