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 /
avatar image
0
Question by Armand · Jul 29, 2011 at 11:17 PM · meshbugproceduralinvisible

Procedurally generated mesh randomly appearing invisible

I have a 10x10 grid of cubes, each cube can be either enabled (visible) or disabled (invisible). To avoid both the overhead of instantiating new GameObjects as well as the black lines that sometimes appear between the blocks, I have written a script that combines the cube meshes into a single mesh every time the mesh is changed.

The problem is, the resulting mesh is visible only when it is formed from a full 10x10 grid of blocks. 9x10 or anything smaller will appear invisible. The strange part being, I use the exact same combined mesh for the object's collider, and it works fine. Changing the material or shader has no effect. The inspector will show the wireframe of the mesh at runtime when I look at the generated mesh of a full 10x10 grid, but if it's a 9x10 grid, the wireframe preview is no longer visible.

I don't think the problem is with my mesh combining script, because the collider works as expected, and if I use Mesh.CombineMeshes with the merge submeshes option turned off, the mesh also renders correctly. However, I specifically want to merge the submeshes.

I've tried to figure out a reason for this behaviour for days now and looked up every possible answer here, but have found nothing. Is this a bug?

EDIT:

Also, when I was previously working on this on a (rather ancient) laptop, I noticed the number of batched draw calls going up whenever I was looking at an area with the invisible meshes (when they were small enough to dynamically batch). I tried disabling dynamic batching from the project, and that fixed it on the laptop. However, on my main desktop machine the dynamic batching setting has no effect on the invisibility problem. This kind of so far seemingly random behaviour initially lead me to consider a bug in Unity.

Comment
Add comment · Show 3
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 Joshua · Jul 29, 2011 at 11:50 PM 1
Share

Impossible to confirm without your script or a demoscene. :)

avatar image Waz · Jul 29, 2011 at 11:53 PM 0
Share

Could be normals facing the wrong way.

Could be UVs all in a transparent part of your texture.

avatar image Armand · Jul 30, 2011 at 12:34 AM 0
Share

As far as I know, if the normals were facing the wrong way, the colliders (created from the same mesh) wouldn't work properly. And I just checked the UVs as well, they too seem fine. The texture is dead simple programmer art for now, so it doesn't even have transparent parts :)

2 Replies

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

Answer by Armand · Jul 30, 2011 at 12:02 PM

Well, I think I solved it.

I had cached the mesh of the block (there is going to be different types) in an array, and when combining the meshes it would look up the current mesh for each block. Initially I had set the mesh of a cleared block as null, but in a previous iteration of the system there was some problem with that and I had replaced null with simply an empty new Mesh. That had worked, and as said, the colliders formed nicely. I was experimenting with every possible detail, and decided to try and change the system so that the cached mesh array would use null instead of an empty mesh, and the code would specifically skip trying to add meshes set to null. Now the rendering works as well!

I don't understand why though, as there's no difference that I can notice in the arrays of the meshes before and after applying this. And I still have no idea why dynamic batching or different computers would affect this, but I assume it's a hardware/driver thing and how they deal with textures and meshes. Won't be able to test this on the laptop for a while though, but let's hope this solution is solid :)

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
4

Answer by Eric5h5 · Jul 30, 2011 at 04:30 AM

Use Mesh.RecalculateBounds.

Comment
Add comment · Show 2 · 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 Waz · Jul 30, 2011 at 06:39 AM 0
Share

Yes, despite the docs saying "Assigning triangles will automatically Recalculate the bounding volume", I too have had to explicitly call this.

avatar image Armand · Jul 30, 2011 at 10:02 AM 0
Share

I have been using $$anonymous$$esh.RecalculateBounds from the beginning, it actually seems to work without it, but I wasn't planning on taking it away until the whole system works properly.

Trust me, I've looked through just about any post here tagged with anything that might have something to do with this, and I've tried the basic solutions (clipping planes, frustum culling, render outside the camera etc) :)

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

6 People are following this question.

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

Related Questions

Detail mesh paint is not working! 3 Answers

Creating a mesh "outline" around gameobject messes up when the gameobject rotates... 3 Answers

Strange shading on procedural mesh 0 Answers

Why is my mesh getting messed up 1 Answer

Unity disconnected/flying shadow (peter panning) 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