Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Wenon · Jun 01, 2018 at 08:16 PM · triggerlayersdetection

Different layers not ignore each other with trigger collision

Hello, I made a player with normal collision, in his script is OnTriggerStay which is used to detect various sensors and paths. And There is huge sphere around player as children of player which is used to spawn peds. Sphere collider is trigger. Player and sphere are in different layers, layers sets to ignore each other. But OnTriggerStay in players script still detects collision with this sphere. It makes a lot of calls and drops fps on android to about 20 from 60. How to make OnTriggerStay ignore other collider as trigger which is on diffrent layer which should ignore players layer as I set in physic menu? Even If I set sphere collider as non trigger OnTriggerStay makes calls but much less despite they are on different layers which ignore each other.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by b1gry4n · Jun 02, 2018 at 02:10 AM

https://docs.unity3d.com/ScriptReference/Collider.OnTriggerStay.html ontriggerstay detects every collider regardless of the physics matrix. you need a check in your ontriggerstay

         int layer_index = LayerMask.GetMask("Layer_name_you_want");
         public LayerMask includeLayers;
         void OnTriggerStay(Collider other)
         {
             if(other.gameObject.tag == "compareTag")
             {
                 //it matches the tag we want
             }
             if(other.gameObject.layer == layer_index)
             {
                 //it matches the layer index we chose
             }
             if (((1 << other.gameObject.layer) & includeLayers) != 0)
             {
                 //it is in the layermask
             }
             if (((1 << other.gameObject.layer) & includeLayers) == 0)
             {
                 //it isnt in the layermask
             }
         }
Comment
Add comment · Show 5 · 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 Wenon · Jun 02, 2018 at 08:11 AM 0
Share

I don't want ignore layer inside OnTriggerStay, I want to OnTriggerStay ignore layer because when Player is inside huge sphere, sphere makes thousands calls on trigger stay in player script and 50 percent of performance decreasing on android because of this even if Ontriggerstay is empty. I hope there is some way for the ontriggerstay to ignore the object

avatar image b1gry4n Wenon · Jun 02, 2018 at 08:15 AM 0
Share

If you are using OnTriggerStay, it will check every collider. Its in the docs i linked. that is just how it works. i have given you 4 different ways you can check to ignore. pick one.

if you dont want to constantly check, do not use ontriggerstay.

invoke repeat a function that overlap sphere casts, check for overlaps then at set intervals.

https://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.InvokeRepeating.html https://docs.unity3d.com/ScriptReference/Physics.OverlapSphere.html

         public float radius = 5.0f;
         public float checkRate = 0.25f;
         public Layer$$anonymous$$ask mask;
         private void Start()
         {
             InvokeRepeating("OverlapCheck", 0.0f, checkRate);
         }
         void OverlapCheck()
         {
             Collider[] hits = Physics.OverlapSphere(transform.position, radius, mask);
             foreach (Collider c in hits)
             {
                 //dostuff
             }
         }


avatar image Wenon b1gry4n · Jun 02, 2018 at 08:23 AM 0
Share

I know how to ignore objects inside function, unfortunately, this is not a solution to the problem

Show more comments
avatar image
0

Answer by michelkong7586 · Aug 10, 2021 at 11:35 AM

Hellow Im Here To Promote My Site Plz Visit My Site Enjoy Thanks

https://www.academicinside.co.uk/curse-of-strahd-pdf/

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 Capsim · Feb 11 at 07:30 PM

We provide nursing assignment writing help service to medical students across all academic levels globally. Try us if you need nursing homework help services.

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

126 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

Related Questions

Sunflare goes through triggerCollider even if they're in same layer 0 Answers

Adds too many points to the score? 0 Answers

I need help with collision detection event 1 Answer

Collision problem when spawning in the collider 1 Answer

Detecting contact on 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