Why is my OnCollisionEnter running twice?

I’m using the Steam VR assets package for the bow. When my arrow hits the target it deactivates the current target. After it is supposed to activate one, but it is calling the OnCollisionEnter twice. So it is activating two most of the time. Here is the code.

private void OnCollisionEnter(Collision other)
	{
		transform.parent.gameObject.SetActive(false);
		Invoke("Target", rnd);
		print("hit" + gameObject.name );		
	}

	void Target()
	{
		int randTarget = Random.Range(0, targets.Length);
		targets[randTarget].SetActive(true);		
	}

Hello there.

when using any function of family “On Collision/Trigger” , you should determinate what object pretend to be dectedt.

This function, in your code, is executed every time a new collider collides, all colliders, terrains, objects, everything…

You should do something like:

 private void OnCollisionEnter(Collision other)
     {
         if (other.name!= "Arrow") return;
         transform.parent.gameObject.SetActive(false);
         Invoke("Target", rnd);
         print("hit" + gameObject.name );        
     }

This way, onbly be executed when an object called arrow collides. You can use any other thing like the tag, or anything you find usefull to determinate is the object that is colliding should execute the function.

Bye.