OnTriggerEnter triggering twice on one collider?

I’m Make a Melee Attack system using a hit box to damage everything close by, i’m doing this by having a collider on my player at the front set to “Trigger”, then im getting a reference to the objects im attacking by adding anything inside it to a list.
The issue is that if i move towards the other object at a certain angle its added to the list twice and im dealing double the damage?
Any idea why its doing it? :slight_smile:

It could be a Physics setup issue. It the hit box is a mesh collider, try ticking Convex. Also, depending on how you move/animate your character, maybe you can move in FixedUpdate(). I can set up a scenario, for example, that intermittently “double reports” OnTriggerEnter by giving the player a CharacterController that’s moved by CharacterController.Move() in Update().

I also came across this good answer with guidelines on Physics movement and collision detection: Guidelines for using rigidbody, collider, CharacterControllerScript, etc? - Unity Answers

[EDIT 1: Also check that your objects don’t have two or more colliders.]

[EDIT 2: If you’re using rigidbodies, use Rigidbody.MovePosition() instead of changing transform.position directly.]

I’m not sure why it would be added twice to the list, maybe something to do with the melee attack mechanics that you use, but anyway the solution is quite simple - use a hashset instead of a list, that will eliminate all duplicates.

To convert a list to a hashset (hence removing all duplicates):

HashSet<Collider> uniqueCollidrs = new HashSet<Collider>(colliderList);

I’m facing same problem now.

There is two colliders and I use an additional script component to give them types. So when I want to know what exactly one collider have collided to, I do:

void OnTriggerEnter(Collider other)
{
    Debug.Log(other.name)
    switch (other.gameObject.GetComponent<ColliderType>().Type)
    {
        ....
    }
}

Then in log I see “AttackTrigger” name has shown twice, and second is followed by NullReferenceException. For second time it can’t GetComponent() from exactly the same object. This is strange and inconvenient as I have to invent some additional checking for not to fire an event twice.

It seems Destroy(other.gameObject) took too long, so I put a other.gameObject.SetActive(false) before and it solved the problem for me

gameobject[A] has rigibody component,gameobject is a trigger.[A] Initiatively touch .
Don’t write OntriggerEnter into ,please put OntriggerEnter script on [A].
It worked for me!