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 /
This question was closed Aug 22, 2013 at 03:15 PM by meat5000 for the following reason:

Problem resolved. Not a coding issue! Thanks robertbu

avatar image
0
Question by meat5000 · Aug 22, 2013 at 02:02 PM · layermaskoverlapsphere

OverlapSphere, Layermask problems

I can't work out why my layermask isn't working. If I leave it out of the OverlapSphere the function works correctly. With it nothing is returned. All objects are correctly layered and I have tried | instead of || in the layermask.

Layermasks :

 var layerBlock1 : int = 11;
 var layerBlock2 : int = 12;
 var layerBlock3 : int = 13;
 var layerBlock4 : int = 14;
 var layerBlock5 : int = 15;
 var layerMaskTotal : int = ((1 << layerBlock1) || (1 << layerBlock2) || (1 << layerBlock3) || (1 << layerBlock4) || (1 << layerBlock5));


Overlap code:

 var hitColliders : Collider[] = Physics.OverlapSphere(transform.position, 10, layerMaskTotal);
                 for (var col : Collider in hitColliders)
                 {
                     Debug.Log(col.transform.gameObject.name);
                 }

alt text

Any suggestions are greatly appreciated!

layers.jpg (31.9 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

1 Reply

  • Sort: 
avatar image
2
Best Answer

Answer by robertbu · Aug 22, 2013 at 02:30 PM

The operator is a single '|' symbol, not a logical or ('||' ):

var layerMaskTotal : int = ((1 << layerBlock1) | (1 << layerBlock2) | (1 << layerBlock3) | (1 << layerBlock4) | (1 << layerBlock5));

Edit: This comment marked the answer :

These are all public variables, so after the first time they are set, they take their value from the inspector. So check the value in the inspector. Given what you are doing, I suggest you make them all private:

private var layerBlock1 : int = 11;

Comment
Add comment · Show 11 · 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 meat5000 ♦ · Aug 22, 2013 at 02:40 PM 0
Share

Thanks for the reply robertbu; Aye, that's what I read. I've tried it both ways and the results are the same. I'm baffled

avatar image robertbu · Aug 22, 2013 at 02:42 PM 1
Share

Do a Debug.Log() on layer$$anonymous$$askTotal. What is the value?

avatar image meat5000 ♦ · Aug 22, 2013 at 02:46 PM 0
Share

2048 (In both cases | and ||) This was for an updated layermask with an extra layer 16 in there. When I removed it the value was still 2048.

It should be 31744, right?

avatar image robertbu · Aug 22, 2013 at 02:58 PM 1
Share

These are all public variables, so after the first time they are set, they take their value from the inspector. So check the value in the inspector. Given what you are doing, I suggest you make them all private:

 private var layerBlock1 : int = 11;
avatar image robertbu · Aug 22, 2013 at 03:08 PM 1
Share

For Javascript (which you are using), variables are public by default. In C# they are private by default.

If you see them in the inspector (and haven't done anything to hide them from the inspector), they are public.

Show more comments

Follow this Question

Answers Answers and Comments

15 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

Related Questions

OverlapSphere doesn't detect colliders 1 Answer

Does adding a Layermask improve efficieny of Physics.OverlapSphere? 1 Answer

OverlapSphere ignoring all colliders when I use the layerMask parameter. 1 Answer

Replacing OverlapSphere with colliders (Detecting weapon collision with enemies - SOLVED) 1 Answer

OverlapCircleAll, layerMask ( Problem) 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