• 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 bruno martelli_legacy · Jun 19, 2010 at 06:05 PM · cullinglayer

culling & layers confusion

If make a custom layer and I make an object be that layer then I can set the camera to Culling Mask that layer, and it wont show up.

in the docs it says:

// Only render objects in the first layer (Default layer) camera.cullingMask = 1 << 0;

What are the layer numbers? what does << mean? less than 1? why two '<''s

What script would I need to be able to press a key and hide say stuff that was on one of my custom layers?

thanks

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

2 Replies

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

Answer by qJake · Jun 19, 2010 at 06:18 PM

First, read up on Bitshift Operators.

Then, read the Layers page in the Unity docs, that explains how to select different layers.

In your case, you would want to do something like this, if your object was on User layer 8:

Camera.main.cullingMask = ~(1 << 8);

Because 8 is the layer mask your "selective" object is on, and the ~ operator reverses all bits, specifying "all but this layer".

And to reset it to render everything:

Camera.main.cullingMask = ~(0);

Edit:

Since you finally described what you wanted, after an incredibly large amount of comments, this will work if you stick it in Update somewhere. Fill in however many layers you want.

if(Input.GetKeyDown(KeyCode.Alpha1))
{
     Camera.main.cullingMask = 1 | 1 << 8;
}
else if(Input.GetKeyDown(KeyCode.Alpha2))
{
    Camera.main.cullingMask = 1 | 1 << 9; 
}
else if // etc ...
Comment
Add comment · Show 15 · 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 bruno martelli_legacy · Jun 19, 2010 at 06:48 PM 0
Share

Thanks but how do i know what the layer numbers are and also i sort have a bunch of stuff in the scene i want to see, and then some other stuff i need to hide, so how can i show the default and hide/show a custom layer?

avatar image bruno martelli_legacy · Jun 19, 2010 at 06:53 PM 0
Share

ok i get the layer numbers but the bitshifty thing?! thats a brainmelter for me...

avatar image qJake · Jun 19, 2010 at 06:58 PM 1
Share

You don't need to understand that entirely, I just explained that the "8" in the code was your layer number that you want things to be hidden on, and the second piece of code will reset the camera to draw everything.

avatar image bruno martelli_legacy · Jun 19, 2010 at 07:00 PM 0
Share

ive ooked at some other websites for bitshifting and im sorry just dont get it at all. I just want layer 8, or 9, or 10, or 11 and always the default layers. Wouldnt it be easier just to use numbers???

avatar image qJake · Jun 19, 2010 at 07:04 PM 0
Share

You don't need to understand it in order to make your code work. If you want to hide an object, put it on layer 8, and use the first code, which renders everything except layer 8, and if you want to display everything, you use the second code. I think you're making this out to be more complicated than it really is.

Show more comments
avatar image
0

Answer by Guru.du · Jun 19, 2010 at 09:11 PM

This wouldn't so much HIDE stuff on a custom layer but doing something like the following can set it to cull at certain distances taken from: Camera.layerCullDistance page. If, like me, you were just looking to hide things after a certain distance this is much easier. I had been juggling layers in the same way, this is a much cleaner approach to what I was looking for. Hope it helps, if not there are plenty of good suggestions up top.

function Start  ()
{
var distances = new float[32];
// Set up layer 10 to cull at 15 meters distance.
// All other layers use the far clip plane distance.
distances[10] = 15;
camera.layerCullDistances = distances;
}

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

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

No one has followed this question yet.

Related Questions

Render an layer from the position of player to a specific distance 0 Answers

Camera Culling Mask not working as expected? 1 Answer

culling mask on camera ignores layer on lights? 1 Answer

Computational cost of using many Triggers (occlusion culling) 1 Answer

layerCullSpherical 1 Answer

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