Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 chef_seppel · Sep 28, 2015 at 12:02 PM · physicstriggersoverlapsphere

OverlapSphere and QueryTriggerInteraction

Hi,

i my PhysicsManager i turned off "Raycast Hit Triggers". But now i want to include a few trigger colliders in a Physics.OverlapSphere. In the documentation there is this queryTriggerInteraction variable, which looks exactly like what i am looking for. But i cant find i way to use it. I always get compiler errors as if there is no such thing as a fourth variable in the OverlapSphere function.

my (working) code so far, not including trigger colliders: Collider[] hitColliders = Physics.OverlapSphere(position, range, layerMaskSphere);

how do i use the "queryTriggerInteraction" part?

Best Regards chef_seppel

Comment
Add comment · Show 3
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 graciasluigi · Sep 28, 2015 at 01:38 PM 0
Share

By default it uses "UseGlobal". So Physics.OverlapSphere(position, range, layer$$anonymous$$askSphere) is equal to Physics.OverlapSphere(position, range, layer$$anonymous$$askSphere, QueryTriggerInteraction.UseGlobal)

I never really used that, the OverlapSphere works fine with triggers.

What are you trying to achieve? What errors are you getting? Can you detail a little bit more the question?

http://docs.unity3d.com/ScriptReference/Physics.SphereCast.html http://docs.unity3d.com/ScriptReference/Physics-queriesHitTriggers.html

Documentation is lacking for this... =\

avatar image chef_seppel graciasluigi · Sep 28, 2015 at 06:09 PM 0
Share

the thing u said, is exactly what i thought. But it just does not work.

my first try to include triggers was: Physics.OverlapSphere(position, explosionRange, layer$$anonymous$$askSphere, QueryTriggerInteraction.Collide);

but then i get the two errors:

Assets/Scripts/HelperExplosives.cs(32,108): error CS0103: The name QueryTriggerInteraction does not exist in the current context

and

Assets/Scripts/HelperExplosives.cs(32,51): error CS1501: No overload for method OverlapSphere takes 4 arguments

next thing i tried was to put a Physics. in front of the QueryTriggerInteraction. Like this: Physics.OverlapSphere(position, explosionRange, layer$$anonymous$$askSphere, Physics.QueryTriggerInteraction.Collide);

but then i get:

Assets/Scripts/HelperExplosives.cs(32,116): error CS0117: UnityEngine.Physics does not contain a definition for `QueryTriggerInteraction'

and again

Assets/Scripts/HelperExplosives.cs(32,51): error CS1501: No overload for method OverlapSphere takes 4 arguments

it seems to be that the whole QueryTriggerInteraction is not defined. As if i forgot to include something. But i have no idea what.

avatar image Tomer-Barkan chef_seppel · Sep 28, 2015 at 06:12 PM 0
Share

Don't use "Physics.Query..." Just use it by itself, see my answer for exact code. If it doesn't recognize it try "UnityEngine.QueryTriggerInteraction". If it still doesn't recognize it - upgrade your unity.

1 Reply

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

Answer by Tomer-Barkan · Sep 28, 2015 at 03:17 PM

Edit: This functionality was added in 5.2!

If you want to perform a OverlapSphere that will activate triggers even though your global setting (in the physics manager) is set not to, just use the following code:

 Collider[] hitColliders = Physics.OverlapSphere(position, range, layerMaskSphere, QueryTriggerInteraction.Collide);

Notice the last parameter, by default if left empty it will be QueryTriggerInteraction.UseGlobal, but we give it the Collide option to override the global value (which you set to ignore).

Comment
Add comment · Show 3 · 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 chef_seppel · Sep 29, 2015 at 05:21 PM 0
Share

Thank you so much! The Solution was not the Code itself but your comment on the other post:

If it still doesn't recognize it - upgrade your unity

The QueryTriggerInteraction is actually a new 5.2 Feature and i declined the last updated out of laziness :) With the new Version everything works fine (except a few other things, buit i will figure that out)

avatar image Tomer-Barkan · Sep 29, 2015 at 06:04 PM 0
Share

Good to know! I modified my answer in case others encounter this.

avatar image 825546651 · Apr 03, 2016 at 03:35 PM 0
Share

I have a same problem with unity4.6 ,what solution can be ins$$anonymous$$d if i dont upgrade my unity.

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

8 People are following this question.

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

Related Questions

Clarification on updates, physics events order and frequency? 1 Answer

Why doesn't the OnTriggerStay2D run? 2 Answers

C# Construct Line Links Over Time 0 Answers

Sphere Collider set to Trigger acts as solid object 0 Answers

Detect collider collision ,identify and access colliding 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