Break object by destroying and initiating, but multiple objects spawned! Please Help!

I want object to break into many pieces once it drops onto the ground.
Yes, the following code worked but instead of instantiating ONE broken model, MULTIPLE models were instantiated.
I wondered what caused the problem. Sometimes it worked, spawning only 1 model, but sometimes 2 or even 3 models are spawned.

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

public class ObjectBreak : MonoBehaviour
{
    public GameObject destroyedVersion;
    public float breakVelocity;

    void OnCollisionEnter(Collision colliion)
    {
        if (colliion.relativeVelocity.magnitude > breakVelocity)
        {
            Destroy(gameObject);
            Instantiate(destroyedVersion, transform.position, transform.rotation);
        }
    }
}

my gues would be that your “destroyedVersion” object is also colliding with your “ObjectBreak” and with that , more collisions are created and more destroyedVersions getting instantiated

Could be colliding with multiple objects, or maybe your object has multiple colliders that are all colliding. Simplest fix here is just set and check a bool flag to mark when you’ve already broken once to avoid doing it again.

Update:
Solved the issue by setting and checking a bool to mark the object is broken or not.

1 Like