Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by pako · Jan 14, 2013 at 06:51 PM · charactercontrolleristrigger

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?

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Doireth · Jan 16, 2013 at 12:34 AM 0
Share

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.

avatar image iwaldrop · Jan 16, 2013 at 12:43 AM 0
Share

It would be my guess that there is a regular collider and rigidbody in the mix somewhere...

avatar image pako · Jan 16, 2013 at 08:10 AM 0
Share

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

avatar image Doireth · Jan 16, 2013 at 12:54 PM 1
Share

Would layer based collisions not suit your needs?

http://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html

avatar image pako · Jan 16, 2013 at 03:47 PM 0
Share

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.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by pako · Apr 16, 2013 at 09:11 PM

After submitting a bug report, I finally received a response from Unity QA:

  1. 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.

  2. 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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Doireth · Jan 16, 2013 at 03:51 PM

http://docs.unity3d.com/Documentation/Components/LayerBasedCollision.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges