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
1
Question by theateist · Mar 30, 2013 at 12:15 PM · gameobjectpathfindinglayers

Is it possible to have multiple layers on one object?

I applied mask1 for planes that construct maps and then using Physics.Raycast(ray, out hit, 1000, mask1) I know if it hit the right layer. On the other hand I want to apply mask2 to some of that planes for Pathfinder from Aron Granberg. But I cannot apply multiple layers for the same object. What I should do?

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
6
Best Answer

Answer by Owen-Reynolds · Mar 30, 2013 at 04:20 PM

Phy.raycast(.., mask1 | mask2) will hit anything selected by mask1 or 2. Or, you can make the mask directly. Say you want to hit layer 8 and 12 -- int layer8n12Mask = 1<<8 | 1<<12;

If you need the ray to hit all of 8, but only some things on 12 (the ones you wanted to put on 8 and 12,) but not the rest of 12. You have to split them out. Maybe make layer 14 be the "count as 8+12" layer. For pathfinding, you can check 12 and 14 in the list. For ray casts, can use mask8 | mask14.

Comment
Add comment · Show 7 · 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 Fattie · Mar 30, 2013 at 04:23 PM 0
Share

indeed ...

avatar image Fattie · Mar 30, 2013 at 04:41 PM 0
Share

you know you're totally 100% right Owen -- I vagued on it !!! deleted my incorrect answer. hey i believe your thingy just clicked over to "10k"

know any Facebook/P31 experts?! FORU$$anonymous$$ ... WOE cheers!

avatar image theateist · Mar 30, 2013 at 05:02 PM 0
Share

It works! Thank you very much!

avatar image rad1c · Oct 16, 2016 at 01:11 AM 0
Share

2016, v5.4 here, Raycasting is still a pain. Thank you for the great answer, I'll do this in my code (I set layer collisions based on difficulty so I need a dynamic set of 'what hits what' for some rays too). There's another reason -on top of saying thanks- for popping a comment: hopefully Unity devs. will read: would be great if I could cast Physics rays by handing over the "source layer" as a value/variable, so raycasting could use the physics / collision layer I defined / set. Cheers

avatar image Owen-Reynolds rad1c · Oct 16, 2016 at 01:23 AM 0
Share

There's a new Layer$$anonymous$$ask type for people who don't want to learn binary ops, which also allows you to look up layers by name. This old way works (and is better, I think, if you know it.) But pretty much, this answer is obsolete.

avatar image Owen-Reynolds Owen-Reynolds · Oct 16, 2016 at 03:04 AM 1
Share

Ah...the trick is that raycasts aren't from anything, its just code that starts at a point. If the math you used happened to use some gameObject, well, fine, but not relevant.

Yes, the new LayerClass type can take multiple layers by name, and build that mask.

Sounds like you're wanting a feature like Layer$$anonymous$$ask.Get$$anonymous$$askFromPhysicsSettings(layerName);. You could make it with a loop, but you could add a feature request. Seems like a thing they might add.

Show more comments

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

13 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

Related Questions

Destroying an instatiated game object with a script attached creates problems for the rest of instatiated game objects with the same script 0 Answers

How to cover buttons with game objects? 1 Answer

RTS Style Unit: How to surround enemy when attacking 1 Answer

Often when loading level the Layers i have on gameobjects reset to default. Please help? 1 Answer

using Contains(gameObject) to find and destroy a gameObject from a list 2 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