- Home /
Physics.RaycastAll -- No more RaycastHit?
So I've been working in Unity for about a year now, and I just went back to do some raycasting the way I usually do, and then I see this:
I've never seen this QueryTriggerInteraction stuff before, and I no longer see a spot to put any kind of RaycastHit. I've tried this with Linecast, Raycast, and RaycastAll. It all does the same thing.
What's going on? Is Unity trying to get rid of (or has gotten rid of) RaycastHits? How do I do this guys?
Just look at your own screenshot. As you can see at the front the Raycast method has 16 overloads and you're curently viewing the 9th. Just press up / down to cycle through them in the intellisense popup. Intellisense automatically picks the first overload that matches your given parameter count. You currently have 4 parameters (at least 3 commas which means you want to pass 4 parameters at the moment).
RaycastAll never had a parameter for a RaycastHit structure since the method returns an array of RaycastHit.
So in the end nothing has actually changed. They just added a few overloads that take an additional QueryTriggerInteraction enum value.
Answer by Teravisor · Feb 01, 2016 at 09:06 PM
Just use something like
public static bool Raycast(Vector3 origin, Vector3 direction, out RaycastHit hitInfo, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
or
public static bool Raycast(Ray ray, out RaycastHit hitInfo, float maxDistance = Mathf.Infinity, int layerMask = DefaultRaycastLayers, QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal);
In manual Physics.Raycast there are overloads that have out RaycastHit hitInfo
like I've listed above, it's just they're not on top so you have to scroll page down. Your MonoDevelop/VS codehint should have them as well as those that don't have RaycastHit.
Example:
Ray ray = new Ray();//Replace this with proper ray obviously
RaycastHit hitInfo;
if(Physics.Raycast(ray, out hitInfo))
{
//We hit something, so do something. What we hit is in hitInfo.
}
Specifically in your case call is as Physics.Raycast(ray, out hitInfo, 100.0f, lm_GravityZoneMask);
Linecast has overload like that too: Physics.Linecast(start,end,out hitInfo);
I don't know what's problem with RaycastAll as manual states it still returns RaycastHit[] and my VS sais same.
QueryTriggerInteraction defines whether this raycast should hit isTrigger colliders or not. By default it uses global setting (Physics.queriesHitTriggers).