How do you get OnTriggerEnter to register?

Hi,

I’ve read the documentation and google has no solution.

I have this:

using UnityEngine;
using System.Collections;

public class ConeFader : MonoBehaviour
{
	void OnTriggerEnter(Collider other)
	{
		Debug.Log (other.gameObject.name); //i've tried variations
	}
}

Then that’s on a cylinder attached to the camera, anything that passes through it should trigger the script.

Nothing does. Nothing ever shows up in the console log.

It doesn’t get any simpler… why is this not working? That’s the entire reason it’s there, isn’t it?

I’ve got it set to be a trigger…

Not sure why it’s on the camera, but put a rigidbody on the object with the trigger. I’m assuming you already set the collider to a trigger (with the checkbox) and also use “Is Kinematic” (check the box in the rigidbody options, and might as well uncheck Use Gravity) so the system doesn’t waste time calculating physics on the object.

Still wont work…

The MeshCollider on the object doing the colliding needs to have ‘IsTrigger’ turned off, while the MeshCollider receiving the collision needs IsTrigger turned on. Try making that change and see what happens.

Hm? That’s how it’s already setup. The objects that are colliding are NOT triggers. The object that is emitting from the camera (the cone, that I want objects to collide with) is a trigger.

Edit: I set up a sphere the same way my mesh is setup and it works… so the problem lies with that cone I imported from Maya.

Edit2: Unparenting it from the camera works. But I need it parented to the camera…

Edit3: Because the parent object (character - which the camera is under, which the cone is under) has a rigidbody, it will not detect collisions on child objects…?

Here, let me describe the full proper setup, just to make sure we’re not missing anything…

Cone - The Object to Collide With

  • Receives the ConeFader script
  • Has the IsTrigger enabled
  • Does not have a RigidBody component.

Box - Or anything you want to have collide with the cone

  • Does not have the ConeFader script
  • Has IsTrigger disabled
  • Has a RigidBody

By the way, just to be clear: only one of the objects that are part of the collision need a rigidbody (the player OR the cone).

Also, I’m not sure if triggers are meant to move like that. You may just want OnCollisionEnter- however, I am not an expert on this, but you may as well as try that as you wait for someone with more experience to respond.

Triggers can move, but when you have lots of movement you almost certainly then want to have the Collision Detection on the RigidBody set to Continuous.

Ahhh, that would make sense. I remember going through a tutorial where I had to change that, but I never actually used it.

By the way, Vire, setting the Detection to Continuous uses more resources but is more accurate (a decent trade-off).

What he said. :slight_smile:

I edited my response without refreshing, doh, anyway, because the player has a rigidbody the child objects’ rigidbodies wont work. So this means the player needs to be set to trigger? I don’t want him to be a trigger…

Edit: Guess I’m still confused. Why is my collision not working? The parent object actually doesn’t have a mesh collider at all because it’s an empty node with the scripts on it.

You guys are trying to explain why it wont work but there is no solution to the problem then?

Is the player colliding into the cone, or is the cone colliding into the player? (The best setup is for the player to collide into the cone and other objects, not the other way around.)

Suppose I should explain what it’s doing…

The cone is being used instead of a ray to cover a wider area. Anything that enters the trigger fades out, and OnTriggerExit to fade back in after… The player’s collision will not be considered once I’ve scripted it in.

Maybe I’m doing everything wrong, who knows. I’m new to this.

Oh well, guess this way isn’t possible.

It’s entirely possible. Follow the example I gave above and see how it goes. :slight_smile:

That’s how I’ve been doing it already, though. And like I said, it works if it’s not under a parent. The issue is the parent, not the collider or trigger. There’s nothing on the parent I can change without screwing my character.

Removing the rigidbody from the player “fixes” it. But I kind of want that on there…

Does the cone have a rigidbody? Try to keep the player’s rigidbody but remove the one on the cone.

Yes, I’m grasping at straws right now. And it seems like then it’s not an issue of it being under a parent necessarily.

I removed the one on the cone. Basically it comes down to: Does the player have a Rigidbody? Yes, then it wont work. No, then it will work.

What the heck! If I move the camera to be obstructed, the obstructing object is not considered to have entered the trigger unless THAT object moves!

All my effort is wasted if there’s no solution.

This system is ATROCIOUS.

Need collisions? Need adequate terrain? Need adequate controller input? Don’t even bother with unity it seems.

We gave you the answer man… calm down.

Yes, the player has to have a rigid body.

Does the actual player have to have it? No.

Create a GameObject, make it a child of the Player, and put the RigidBody and colliders on that. Then the player will appear to collide with the object. This is a very common method used in many game engines.

Alright, thanks.