• 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 /
  • Help Room /
avatar image
0
Question by toyester · May 31, 2017 at 02:47 AM · raycastlayersraycasthitlayerlayermask

My layers seem to be completely broken

Hi so I've been using ray-casts and layers fine for the past few months in a project of mine, but now they seem completely unpredictable and broken.

To make sure I wasn't going completely insane I created a new scene with just a cube in it, I gave the cube a different layer and tested the outcome multiple times.

So I made a script so that when I right click on the cube, I print out what layer I hit. Here is the result for the "Default" layer.

alt text (the 12 results for "ray hit cube" is for layers that don't even have names yet I presume)

Also here is the script I'm using to test this, along with my layers

 public class LayerTest : MonoBehaviour
 {
     void Update()
     {
         if (Input.GetButtonDown("Fire1")) //user has just clicked LMB
         {
             Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             RaycastHit hit;
             for (int i = 0; i < 32; i++)
             {
                 if (Physics.Raycast(ray, out hit, Mathf.Infinity, i))
                 {
                     Debug.Log("ray hit " + hit.transform.name + LayerMask.LayerToName(i));    
                 }
             }
         }
     }
 
 }

alt text

I am using unity 5.4.1, also if needed I can post the results for the rest of the layers, however only the following layers would prompt a print

  • Default

  • Ignore Raycast

  • TransparentFX

  • Water

Thanks in advance for any help.

unitydefaultlayertest.png (134.0 kB)
unitylistoflayers.png (23.6 kB)
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

131 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make raycast only collide with two layers? 2 Answers

Allow raycast to skip an object with rigidbody 0 Answers

Ignore Raycast not working properly? 0 Answers

Unable to click UI button, tried everything I could find 1 Answer

Raycast hitting layer explicitly told to ignore (and doesn't even have collider!) 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges