- Home /
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
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... =\
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:
andAssets/Scripts/HelperExplosives.cs(32,108): error CS0103: The name QueryTriggerInteraction does not exist in the current context
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:
and againAssets/Scripts/HelperExplosives.cs(32,116): error CS0117: UnityEngine.Physics does not contain a definition for `QueryTriggerInteraction'
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.
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.
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).
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)
Good to know! I modified my answer in case others encounter this.
I have a same problem with unity4.6 ,what solution can be ins$$anonymous$$d if i dont upgrade my unity.
Your answer
Follow this Question
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