Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Feb 08, 2016 at 05:45 PM by Le-Pampelmuse for the following reason:

The question is answered, OP unresponsive

avatar image
2
Question by xxluky · Dec 07, 2015 at 03:58 PM · renderingviewportdisable object

How to disable objects that are outside viewport?

Hi,

I tried hard to figure out how to hide whole gameobjets with sprite renderer for performance reasons. Disabling only the sprite renderer does do nothing with performance. I need to disable the whole object that is not seen by the Main Camera and activate it again when seen.

My problem is that I have a cript using update method and check if the object is visible by

 bool visible = GetComponent<Renderer>().isVisible;

but when the object is deactivated, Update is not called anymore so the object is never set active again when in the viewport...

The script has to be really simple. Sould not be using update because I have a 2D platformer and my scene is build up from hundreds of sprites. I need all sprites turn off when they are not visible.

Comment
Add comment · Show 4
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 Le-Pampelmuse · Dec 07, 2015 at 06:39 PM 2
Share

What you are looking for would be Occlusion Culling.

Regarding frustum culling and general sprite performance:

Having hundreds of sprites should not be a problem. I created a scene with 2500 sprites and the render time is still way below 10 ms (it's around 5ms, or 200 fps).

alt text

2d.jpg (356.2 kB)
avatar image Le-Pampelmuse Le-Pampelmuse · Dec 07, 2015 at 10:52 PM 2
Share

I might add that of course you can do it yourself, but that would involve having one gameobject with a script that is constantly getting a reference of every active/non-active gameobject in the scene and updating that if new gameobjects are created or older ones destroyed, and then for every one of them checking if they are really visible (not just rendered, but really visible for the camera) at the moment and if so, activate them.

I'm not sure if that is what you are looking for since Occlusion Culling is a feature that was "invented" many years ago for just that reason.

Then again, you can do it manually, but I don't recommend it since the functionality is already native to the engine and ready to use.

Hope you are happy with this, if not, feel free to describe what exactly you want to achieve.

avatar image SumFortyOne Le-Pampelmuse · Jan 15, 2016 at 03:39 AM 1
Share

This picture gave me a head ache :P

avatar image Le-Pampelmuse · Dec 08, 2015 at 07:29 PM 1
Share

If you read the description of one of the images in the occlusion culling page, it says:

Regular frustum culling only renders objects within the camera’s view. This is automatic and always happens.

1 Reply

  • Sort: 
avatar image
0

Answer by 1MachoKualquiera · Dec 08, 2015 at 11:57 AM

Maybe you can estimate the coordinates that are outside the viewport, and then say

 for (int i = 0; i < gameObject.getGameObjectsWithTag("disable?"; i++)
 {
   if (transform.position.x < camera.transform.position.x - [outside the camera])
   {
    //disable the object
   }
   if (transform.position.x > camera.transform.position.x + [outside the camera])
   {
    //disable the object
   }
   //... (the same with y axis)
 }

This is just so you take it as an idea, obviously not real code :)

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

Follow this Question

Answers Answers and Comments

36 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Alignment Issues with HP bar 0 Answers

ScreenToWorldPoint() not working properly using a RenderTexture 1 Answer

CaptureScreenshotAsTexture behave differently than CaptureScreenshot 1 Answer

PLease help, I need to render a particle system on top of an overlay but behind the buildings ,PLease help with render on top of sprite renderer but behind of another 0 Answers

How to continue material between sprites. 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