Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 bakos · Dec 28, 2013 at 10:40 PM · raycastlayers

Set transform layer

Hey there :D

I am curious, is there a way to set a Transform's layer?

I have a building preview object, which instantiated correctly(FINALLY), but I cannot set its layer to ignore raycast.

Thank you for reading, Sincerely,

Bakos133

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

1 Reply

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

Answer by PlasmaByte · Dec 28, 2013 at 11:30 PM

You can set a gameobjects layer in the top right of the inspector window (just under the name). You can make new layers for your game if you want. To then ignore the layer you need to include a layer mask while raycasting (a binary number with 1 to include a layer and 0 to ignore it).

The following raycast ignores layer 8 (shift a 1 eight bits to the left and then invert it).

 RaycastHit hit;
 float distance = 1000;
 int layerMask = ~(1<<8);
 if (Physics.Raycast(ray, out hit,distance, layerMask)){
 
       //do cool stuff
 
 }
Comment
Add comment · Show 4 · 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 bakos · Dec 29, 2013 at 02:00 AM 0
Share

Excellent answer man! I am just curious if there is a way to set the layer of a transform in a similar manner as setting the layer of a gameobject.

eg.

gameObject.layer = 1;

avatar image PlasmaByte · Dec 29, 2013 at 09:48 AM 0
Share

I don't think you can have a separate layer for different components on the gameobject. What are you trying to achieve?

avatar image bakos · Dec 29, 2013 at 05:12 PM 0
Share

I've got a block building game, and I need the "Preview" block to be semi transparent and be in the "Ignore Raycast" layer. So I can see the block i am going to place, and still place it where required without my preview getting in the way.

avatar image PlasmaByte · Dec 29, 2013 at 05:36 PM 0
Share

Ah, I would use a separate object for the preview block and just change the mesh and material depending on the thing you currently want to build. Then instance the new block when you click confirm.

If your making a $$anonymous$$ecraft style game you won't want to have your blocks as separate objects anyway, far too resource intensive. You'll need to "chunk" it.

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

19 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

Related Questions

Finding all Objects by Layer within X Radius of Player? 1 Answer

Why wont Raycast wont ignore layer? 1 Answer

Raycasthit info only working the first time the object is hit 1 Answer

Usage of Layer masks, what am I doing wrong? 1 Answer

The Child Is Not Hovered When Passing The Parent's Collider 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