• 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 reissgrant · Nov 27, 2010 at 06:37 PM · cullinglod

MeshFilter swap does not work with static mesh

I'm trying to combine mesh filter LODs with Umbra culling.

The LOD is a script that swaps sharedMesh based on camera distance, i.e. very basic:

/////////////////////////////////////////////////

if( (transform.position - campos).sqrMagnitude < distance * distance ) { // use high LOD if( meshFilter.sharedMesh != highLod ) meshFilter.sharedMesh = highLod; } else { // use low LOD if( meshFilter.sharedMesh != lowLod ) meshFilter.sharedMesh = lowLod; }

/////////////////////////////////////////////////

This works perfectly when the mesh is not static, however as soon as the mesh is set to static for culling calculation, it stops working. By not working, I mean that the hundreds of instances of the mesh's transforms are reset and all are placed at 0,0,0.

How can I properly combine mesh LOD with culling?

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
1
Best Answer

Answer by Paulius-Liekis · Nov 29, 2010 at 02:44 PM

If you're swapping a mesh then it isn't really static. When you mark objects static you "make a promise" to Unity that your object will be STATIC, i.e. you won't move them around and so on, then Unity can precompute some things (like apply transform to the mesh).

I don't think you need make objects static in order to have culling. Culling works in any way. IIRC, depending on Static Unity does static or dynamic batching.

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

Answer by reissgrant · Nov 27, 2010 at 09:26 PM

I changed the code to enable / disable the renderer rather than swap out the mesh.

I can now set the object to static and use culling with no problems.

I have a parent with two gameobjects, (hi and low poly versions), I then place the LOD script on the parent and assign the hi / low versions, set to static then save as prefab.

Script:

/////////////////////////////////////////////////

 var highLod : GameObject;
 var lowLod : GameObject;
 var distance = 10.0;

 function Update ()
 {
     var campos = Camera.main.transform.position;
     if( (transform.position - campos).sqrMagnitude &lt;
         distance * distance )
     {
         // use high LOD
         if( highLod.renderer.enabled == false){
             lowLod.renderer.enabled = false;
             highLod.renderer.enabled = true;
         }
     }
     else
     {
         // use low LOD
         if( highLod.renderer.enabled == true){
             highLod.renderer.enabled = false;
             lowLod.renderer.enabled = true;
         }
     }
 }


/////////////////////////////////////////////////

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 Paulius-Liekis · Nov 29, 2010 at 02:41 PM 0
Share

$$anonymous$$ark your answer as correct one if it solves your problem ;)

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

LOD system with Partial object culling? 2 Answers

GameObject disappear as I move/rotate the camera 1 Answer

Culling/Vanishing point for aerial views in large scenes 1 Answer

Culling faces from models in the unity editor viewport? 1 Answer

Object Fade at distance 0 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