- Home /
The question is answered, right answer was accepted
OnCollisionEnter and OnTriggerEnter not working
I am instantiating an prefab arrow and shooting it through a Trigger into the Terrain but neither OnTriggerEnter or OnCollisionEnter trigger at all. The arrow has a Rigidbody attached and is not Kinematic while Flying. I have no idea whats wrong at this point.
The Arrow has a this Script. It is active as soon as the arrow gets Instanciated and does not get deactivated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EmbededBehavior : MonoBehaviour {
Rigidbody rigidB;
// Use this for initialization
void Start () {
rigidB = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update () {
}
private void OnCollisionEnter(Collision col)
{
Embed();
transform.parent = col.transform;
Debug.Log("OnCollisionEnter");
}
private void OnTriggerEnter(Collider col)
{
Embed();
transform.parent = col.transform;
Debug.Log("OnTriggerEnter");
}
void Embed()
{
transform.GetComponent<ProjectileAddForce>().enabled = false;
rigidB.velocity = Vector3.zero;
rigidB.useGravity = false;
rigidB.isKinematic = true;
}
}
I tried to reproduce your problem using Unity Terrain and a GameObject with a suitable script. However, both OnTriggerEnter and OnCollisionEnter get called properly.
The problem is very likely with your setup.
You should post more info.
I had this problem yesterday, and it turned out it had nothing to do with scripting. By chance did you change anything in Edit > Physics within Unity?
For me it was that i just had a Rigidbody on it not a box collider that's why it didnt trigger
Answer by JanWdm · Feb 12, 2018 at 04:49 PM
Was missing a collider on the Object that's why it didnt trigger
Follow this Question
Related Questions
Change NavMesh Speed after collision/trigger just for 1 object 1 Answer
Trying to make object turn red OnTriggerEnter 0 Answers
Triggering sounds on collision?,Rigged Character animation collision 2 Answers
2D collision not registering 1 Answer
Mesh collider problem with two models next to each other 0 Answers