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 RonHiler · Nov 11, 2012 at 03:30 PM · cullingvisibilityonbecamevisible

OnBecameVisible() not working as I'd hoped

Hey guys,

I need to know if a game object is visible on the screen. And I mean actually visible to the camera such that the player can see it, not behind a wall or whatever. I was hoping that OnBecameVisible() would do the trick for me.

But it turns out this message fires whenever the object enters the camera's view frustum, irregardless of depth culling. I put the object three rooms away behind several environment walls, there is no way it is visible to the camera (and yes, I made sure the editor camera was not pointing at the object).

I even tried making it static (along with the environment) and trying to use occlusion, but it's still firing that message inappropriately. I did turn off shadow casting/receiving on that object just in case, but that didn't help.

Any suggestions? Is there any way to know if an object is depth culled? If I could use some combination of OnBecameVisible() along with some sort of IsDepthCulled flag, that would seemingly do the trick, but I suspect Unity has no idea, since depth culling is done on the GPU, so I may be out of luck there.

I realize I could use a line cast (object transform to camera tranform) to look for collisions, but I think I will have too many of these objects for that to realistically work (potentially thousands of them). So I'm out of ideas, do I have any other options?

Comment
Add comment · Show 2
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 GerryM · Nov 11, 2012 at 05:17 PM 0
Share

Unless you do use occlusion culling, your object will still be drawn (and overdrawn), thus .isVisible will be set.

Just out of curiosity: why would you want to know for lots of objects?

Good luck with a solution, however.

avatar image RonHiler · Nov 11, 2012 at 06:58 PM 0
Share

It's for a mapping system I'm working on.

Unfortunately, occlusion just isn't giving me reliable results. The message doesn't fire quite as often, but it still fires long before you could ever actually see the GO (and through walls). I guess that is probably due to the way the occlusion cells are set up.

I'm suspecting I'm going to have to line cast, which is a bummer. Unless there is maybe a shader solution? I don't know much about that aspect of shaders, can the pixel shader send a message back to the engine?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CostelloNicho · Nov 11, 2012 at 03:58 PM

The Renderer has an "IsVisible" flag -> Renderer.isVisible, which might work well for you in this situation.

Link: Unity Render.isVisible

Comment
Add comment · Show 1 · 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 RonHiler · Nov 11, 2012 at 04:31 PM 0
Share

Thanks for the answer, Syntinel, but unfortunately Render.IsVisible is giving me the exact same problem as OnBecameVisible() does. It doesn't respect depth culling, reporting as visible through environment walls.

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

11 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

Related Questions

How do I trigger the visibility of an object through OnBecame(In)visible? 0 Answers

Is there a way that I can control the maximum number of Visable Skinned Mesh? 0 Answers

dynamic mesh keeps disappearing 2 Answers

How not to render a specific object ? 1 Answer

How to determine if a mesh is on screen. 1 Answer


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