Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
9
Question by user-297 (google) · Nov 24, 2009 at 08:47 PM · physicseditorlayers

What is the purpose of layers?

Why I want to use layer for? I know I can isolate GO (Game object) from the scene, but to do what? Why doing that?

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

3 Replies

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

Answer by Ehren · Nov 24, 2009 at 08:55 PM

From the docs:

Layers are most commonly used by Cameras to render only a part of the scene, and by Lights to illuminate only parts of the scene. But they can also used by raycasting to selectively ignore colliders.

Tags are similar to layers, in that you can use them to mark/group GameObjects. However, tags are "intended to identify GameObjects for scripting purposes," while layers are "used to define how Unity should render GameObjects in the Scene."

If you need to identify certain objects from your scripts (such as enemies, asteroids, walls, etc.), use Tags. If you need to control how certain GameObjects are rendered, use Layers.

Comment
Add comment · 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
3

Answer by Gabriel · Nov 25, 2009 at 05:03 AM

Also, selective raycasting - as in only raycasting against colliders in specific layers as opposed to raycasting against all colliders.

Example:

void TestLineOfFire () { LayerMask mask = 1 << LayerMask.NameToLayer ("Friendlies") | 1 << LayerMask.NameToLayer ("Enemies");

 weapon.willHitSoftTarget = Physics.Raycast (
     transform.position,
     transform.forward,
     weapon.maximumRange,
     mask
 );

}

For more information on masks and layer masks, check out the How do I use layermasks? question.

Comment
Add comment · 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
0

Answer by Goody! · Dec 15, 2009 at 12:37 AM

Gabriel, can you please explain a bit about selective raycasting? I can't find anything about it in the docs.

Comment
Add comment · Show 3 · 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 Bampf · Dec 15, 2009 at 12:15 PM 0
Share

For examples see the page on Unity Layers, near the bottom: http://unity3d.com/support/documentation/Components/Layers.html All the Physics.Raycast calls take a layer mask as an optional argument. The mask lets you test for a hit against objects in only some of the layers, rather than all.

avatar image AngryAnt ♦♦ · Dec 16, 2009 at 09:26 AM 0
Share

I added the description - along with a code example to Gabriels answer.

avatar image Goody! · Dec 17, 2009 at 02:25 AM 0
Share

Excellent! Thank you both!

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

No one has followed this question yet.

Related Questions

Stop raycast from hitting same gameObject twice 2 Answers

How to achieve this basic physics effect? Detect when to change layers 2 Answers

Editor/Player Physics difference 1 Answer

Physics.IgnoreLayerCollision - Help 2 Answers

Physics ignore layer collision script error 3 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