- Home /
Character Controller Collider set to isTrigger
The Character Controller is a Collider. So, in theory it should be possible to be set as a trigger. However, in practice if you set it as a trigger through script (not possible in the Inspector), its behavior is weird. You cannot go through it (as you would a trigger), but yet it triggers OnTriggerEnter events (randomly).
The scripting reference, shows that isTrigger is an Inherited member/Inherited Variable for CharacterController. So, the following script:
using UnityEngine;
using System.Collections;
public class SetTrigger : MonoBehaviour
{
private CharacterController controller;
// Use this for initialization
void Start ()
{
controller = GetComponent<CharacterController>();
controller.isTrigger = true;
}
void OnTriggerEnter(Collider other)
{
print("Trigger was Hit");
}
}
...when attached to a game object with a character controller should make it behave as a trigger... ... but it doesn't.
In fact, when debugging this, it can be seen that the CharacterController gets isTrigger set to true. However, a First Person Controller (with another Character Controller) stops upon collision, instead of going through it (as a trigger). Nevertheless, it fires -occasionally- an OnTriggerEnter event.
Is this a bug? Am I missing something, or what?
I'm given to understand that character controllers use a specialized collider. This collider has characteristics such as being always oriented to the global "up" vector.
So, while never having tried to set a character controller to be a trigger it doesn't seem like this is a bug.
If you could better explain why you are trying to use a cc as a trigger there is likely a better alternative.
It would be my guess that there is a regular collider and rigidbody in the mix somewhere...
Thanks for your responses.
Actually, my interest in this arose from trying to answer someone else's question:
http://answers.unity3d.com/questions/380368/character-controller-pass-throught-another-charact.html
@Legend-of-Hibiki wanted his character controller to pass through another character controller, while using controller.move() to move.
It kind of seemed straight forward to set the character controller to isTrigger through script, as this is an inherited property (per script reference). This actually worked: I attached $$anonymous$$onoDevelop to the Unity process, set a break point, and exa$$anonymous$$ed the variables at run time (for the above script). As expected, controller.isTrigger turned from false to true as soon as Start() completed execution.
I then moved my First Person Controller (SetTrigger script NOT attached), and hit another game object with a Character Controller and SetTrigger script attached, the following happened:
a. Upon collision movement stopped, i.e. my FPC did not go through the other object b. Only on a few of the collisions the OnTriggerEnter event was fired.
Also in the Reference $$anonymous$$anual for the Character Controller:
http://docs.unity3d.com/Documentation/Components/class-CharacterController.html
...at the bottom of the page, under "Hints", the last Hint says:
"Note that changing Character Controller properties in the inspector will recreate the controller in the scene, so any existing Trigger contacts will get lost, and you will not get any OnTriggerEntered messages until the controller is moved again."
I don't change any CC properties in the Inspector, so this note might not be applicable (or it might?). But in any case, this note seems to imply that the CC can be set as a trigger, only it doesn't seem to behave like one.
Although @Legend-of-Hibiki found a work around for his problem, I am trying to understand why this doesn't work.
P.S. No rigidbody or regular collider used
Would layer based collisions not suit your needs?
http://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html
Yes Doireth, Layer based Collisions do solve Legend-of-Hibiki's problem.
I have worked with Layer based Collisions quite a lot, and somehow I just didn't make the connection with his problem, and I started thinking about triggers...
So, the issue in this question is why the CC can't be set as a trigger, and I think I will take it directly to Unity's Support, to see what they have to say about it.
However, as I don't want to take credit for your idea, I suggest that -if you like- you post it as an answer to Legend-of-Hibiki's question. I think it's a much better solution that his current work around:
http://answers.unity3d.com/questions/380368/character-controller-pass-throught-another-charact.html
Thank you for the friendly push in the right direction.
I'll post here the response I get from Unity.
Answer by pako · Apr 16, 2013 at 09:11 PM
After submitting a bug report, I finally received a response from Unity QA:
Although the isTrigger flag of the CharacterController can be set to true in script, the CharacterController is not meant to be used as a trigger. Setting of the isTrigger flag in script will be disabled by Unity.
CharacterController inherits several members from Collider, i.e. isTrigger, OnTriggerEnter, OnTriggerExit, OnTriggerStay. However, these should not be used in code. Unity will update the relevant documentation to clarify this.
Your answer

Follow this Question
Related Questions
How to go through by Charactor Controller? 2 Answers
Rigidbody bounce or character controller istrigger issues 0 Answers
Why is my push rigidbody script not effected by mass? 2 Answers
Touch joystick tutorials ? 0 Answers
Problem detecting ground with collision flags and controller.move (vector3.down) 1 Answer