OnCollisionEnter2D not working (at first)

I really don’t understand why this is happening. I literally have the same code working on some other projectile that works just fine (the one that works is bigger, however).

Here’s my code:

void OnTriggerEnter2D(Collider2D other)
    {
      if(other.gameObject.tag != "Enemy" && !other.isTrigger)
      {
        collider.isTrigger = false;
      }
    }

    void OnCollisionEnter2D(Collision2D other)
    {
      otd = other.gameObject.AddComponent<OverTimeDamage>();
      otd.damage = this.damage;
      otd.timer = this.timer;
      Destroy(gameObject);
    }

Like I said, the other projectile I used this code on works just fine, it triggers first, then it turns the collider to not-trigger in order for it to “truly collide”. Then, in OnCollisionEnter2D, I put the code for damage and whatnot.

Here’s what happens with this thing:


All rigidbodies are dynamic, and all of their collision detections are continuous, I really have no idea what to do.

Just some thoughts, I’m not an expert programmer, but I’ve had similar problems.

I’ve noticed that OnCollisionEnter2D is inconsistent particularly with small colliders, you can watch the 2 items collide but the code never gets called. I’ve gotten around this by placing my code in OnTriggerEnter2D when I notice this happening. My gameobject will have two colliders with one marked as a trigger and the trigger being slightly bigger than the collider. I have not noticed this causing any performance issues and I use primitive shapes for this, then again I’m not making a bullet hell shooter.

You might be able to do this by placing another circlecollider2d on your venom that is smaller than the trigger collider, and moving all of your code into OnTriggerEnter2D and putting a delay in Destroy (gameObject, 0.1f) that will allow the collision to still take place between the full colliders before the venom actually gets destroyed, could also place some boolean logic to ensure that OnTriggerEnter2D only gets called once.