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 /
  • Help Room /
avatar image
0
Question by LoopusLazuli · Feb 17, 2021 at 08:32 PM · charactercontrollercollision detectiontriggersboxcollidercapsulecollider

Enemy CharacterController stopped detecting all triggers, but Player's CharacterController still detects and fires the same triggers

I have a Player prefab with a Character Controller component that when it overlaps the trigger for a pressure plate, the OnTriggerEnter method is called. However, I also have a Sheep prefab with a Character Controller component that does not call the OnTriggerEnter method though it did yesterday (despite not changing any properties for this pressure plate or Sheep's triggers script).


I'm at a total loss as I have tried everything from ensuring the method declaration is spelled correctly private void OnTriggerEnter(Collider other) to making sure the "isTrigger" box is ticked for the BoxCollider on the pressure plate. I also tried adding a RigidBody that is kinematic to the Sheep prefab and then to the Pressure Plate prefab but to no avail. Any help would be greatly appreciated.


Sheep Prefab: alt text

The Sheep prefab has just a CharacterController with the exact same property settings as the Player prefab other than the height. As I understand it, the CharacterController component has a RigidBody so I don't need to add one for the collision system to work (as I have done with the Player).


Pressure Plate Prefab: alt text


Each Cube on the Pressure Plate including the base has a BoxCollider with "isTrigger" unticked. Only the Trigger child GameObject has a BoxCollider with "isTrigger" ticked.


PlayerTriggers.cs (attached to Player)

 public class PlayerTriggers : MonoBehaviour
 {
     PlayerMovement movement;
 
 
     private void Awake()
     {
         movement = GetComponent<PlayerMovement>();
     }
 
 
     private void Start()
     {
         Physics.IgnoreLayerCollision(gameObject.layer, Layers.SHEEP);
     }
 
 
     private void OnTriggerEnter(Collider other)
     {
         print("PLAYER ON TRIGGER ENTER------------------------");
 
         if (other.CompareTag(Tags.SPRING))
         {
             movement.Spring(other.GetComponent<Spring>().GetForce());
         }
     }
 }



SheepTriggers.cs (attached to Sheep):

 public class SheepTriggers : MonoBehaviour
 {
     private SheepMovement movement;
 
 
     private void Awake()
     {
         movement = GetComponent<SheepMovement>();
     }
 
 
     void OnTriggerEnter(Collider other)
     {
         print("TRIGGER---------------------------");
 
         if (other.CompareTag(Tags.SPRING))
         {
             movement.Spring(other.GetComponent<Spring>().GetForce());
         }
 
         if (other.CompareTag(Tags.PRESSURE_PLATE))
         {
             movement.SetIdle(true);
             
         }
 
         if (other.CompareTag(Tags.CONVEYOR_BELT))
         {
             movement.AddVelocity(other.GetComponent<ConveyorBelt>().GetVelocity());
         }
     }
 }


When the Player moves onto the Pressure Plate, the debug console prints PLAYER ON TRIGGER ENTER------------------------, but for the Sheep it prints nothing. Any ideas? Is there something I'm missing here? Thanks so much!

pressureplateprefab.png (174.3 kB)
sheepprefab.png (171.7 kB)
Comment
Add comment
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

1 Reply

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

Answer by LoopusLazuli · Feb 25, 2021 at 04:32 PM

The issue had to do with collision layers. The Sheep prefab is on the "Sheep" layer and based on the Layer Collision Matrix in the Project Settings (Layer-based Collisions), the Sheep would only register collisions with one another. By setting the Sheep's collision layer to Default, OnTriggerEnter worked once again.


In summary, if your triggers aren't registering collisions, there are a few things to try:


  1. Ensure the OnTriggerEnter method declaration is correct using autocomplete or otherwise. The correct declaration is private void OnTriggerEnter(Collider other) {}.

  2. Only one of the colliders can be a trigger ("isTrigger" property is enabled). PhysX does not recognize collisions between two triggers (Collider.OnTriggerEnter).

  3. One of the GameObjects involved in the collision must have a RigidBody (can be kinematic), or a Character Controller component.

  4. And finally, be mindful of your collision layers and how they interact. Are these collisions ignored? Are they enabled through Layer Collision Matrix (as detailed above)?


Hopefully this helps someone. Happy developing everyone! Make something awesome!

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

175 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

FMOD Parameter Change Triggers Not Working, but only in one Scene? 1 Answer

Assiging character controllers capsule collider to cloth? 2 Answers

Why is OnTriggerExit not firing? 3 Answers

My gameobjects collide though they are not near eachother 1 Answer

CharacterController gets stuck between two or more box colliders 0 Answers


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