raycast ignore trigger colliders?

Hi. I am currently working on an fps game. I have created some triggers for instantiating enemies and sound effects. I have also created a weapon script that uses raycast to instantiate bullet hole prefabs, knock rigidbodies over and send a damage message to the enemies. My triggers block the raycast message and instantiate a bullethole in mid-air if I shoot at them. How do i make the raycast completely ignore the trigger colliders?

To have your raycasts ignore all trigger colliders in 5.2 and up, go to (still correct in Unity 2021):

Edit > Project Settings > Physics > Uncheck “Queries Hit Triggers”

(If you’re using an older version of Unity, the check box is called “Raycasts Hit Triggers”)

I know this is an old topic, but seeing as its the first result when googling the problem it should still be helpful.

If you have alot of raycasting third party libraries it can be dangerous chaning the global setting like Okido suggest. Instead supply QueryTriggerInteraction.Ignore to the raycast method

Actually in version 5.2.0f3 it no longer says Raycasts… It now appears as: “Queries Hit Triggers” Uncheck if you want raycasts to pass through trigger colliders.

you can use the last parameter of the raycast function, put this “QueryTriggerInteraction.Ignore” as the last parameter in the raycast function.

I recently had a similar problem.

Go to Edit → Project Settings → Physics2d and Uncheck the box that says “Raycasts Start In Colliders”.

This will let you ignore the colliders on the gameobject casting them.
This makes it so that you do not have to deal with layers (I find layers to be a very impractical way of selectively raycasting). It just ignores the collider on the gameobject casting the ray, so you can have multiple prefabs of players/enemies casting rays and hitting each other, but not themselves.

However, to ignore trigger colliders, please use Okido’s suggestion.