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 anwserman · Jul 30, 2012 at 08:02 PM · triggercullinglayerbasicocclusion

Computational cost of using many Triggers (occlusion culling)

Since I'm using Unity Basic and developing for iOS, I need to make sure to optimize the rendering of my scene. Since I'm too lazy to deal with octrees and other correct ways of culling the objects on the screen (plus I'm still relatively new to Unity!) I've decided to use many, many triggers.

Here's my setup:

  1. Create two layers, "Player" and "Optimization"

  2. Set layer collision matrix so that "Optimization" can only collide with "Player"

  3. For each GameObject in the "Optimization" layer, add a Trigger Collider to it with a script

When my player collides with an object, "OnTriggerEnter" gets called and I activate the GameObject's immediate children.

When my player exits an object, "OnCollisionEnter" gets called and I deactivate the GameObject's immediate children.

With how Unity allows parenting and children, I can increase/decrease these Trigger boxes in size. So, I could make one really big trigger that contains several smaller triggers, which then in turn, turn on and off when the player moves between them. Since this only works when the player hits a collider, it doesn't rely on Update or any other frame-intensive processes. Basically, this is a way to do octree-searching and culling through the physics engine, and not through algorithms and other code.

So --- what are the possible problems with this? I'm thinking script management might be a nightmare compared to other methods, but I think I got it down pat with a basic abstract class for everything so I can extend the functionality for various types of objects without having to rewrite completely new and unrelated scripts.

That being said, what drawbacks are there to relying on Triggers so much (or is this kinda what they are for?)

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
0

Answer by ScroodgeM · Jul 30, 2012 at 10:25 PM

what exactly do you want to optimize? object's function or rendering? or may be physics?

for rendering (i think you rather mean rendering) you simply can use camera far clip plane - all object that are far from camera will no render.

also, you can set far clip plane different for different layers. small objects can be clipped with less distance

you can use simple shaders and geometry (LODs) for big objects at far distances

you also can use lightmaps instead of real-time shadows

Comment
Add comment · Show 4 · 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 anwserman · Jul 31, 2012 at 01:28 AM 0
Share

Update scripts. NPC's and the like

avatar image ScroodgeM · Jul 31, 2012 at 07:21 AM 0
Share

to optimize scripts performance you should disable everything you needn't at moment and to make simple functions anywhere you can. use cheap calculations, coroutines ins$$anonymous$$d of updates, etc

avatar image anwserman · Jul 31, 2012 at 07:25 AM 0
Share

Yes! I'm aware of that fact, and that's why I'm trying to optimize my code now. But the problem with using draw distance alone is that in a scene with 200 NPC's around, I cannot have them all running at once if they're all within the draw distance. For big pieces of scenery, that's fine - they're just static meshes. But I need something to cull other 'active' objects so that Updates aren't wasted on them - I hope that by using triggers, I can keep objects next to the player active and then cull out the rest.

avatar image ScroodgeM · Jul 31, 2012 at 07:30 AM 0
Share

one more way to go:

make a something like 'WaitingFactory' class that will receive all active GameObjects and checks for distance between this GO and player. using a Coroutine once a second (5 second, 20 second - depends on gameplay) it should check for distance between GO and Player and disable/enable it.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

lighting occlusion 1 Answer

Occlusion culling at runtime 0 Answers

GUITextures and Triggers 0 Answers

Occlusion Culling Bugs in 3.3 Pro 2 Answers

Detecting if object is Umbra culled 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