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 TheRichardGamer · Jul 28, 2014 at 04:04 PM · transformmeshrendergenerationworld

How to render only the visible meshes of the blocks?

Hi, so my world generation script is working just fine but there is a problem that is causing lag and that is that when I instantiate too many objects it becomes laggy, I mean I have an area of about 40x40 blocks and it lags just then, and the reason to that is because I'm instantiating, but however, if there's any way to display only what's visible and not render all the other sides of the blocks then that would save a lot of performance power, but how do I do that? Do I make a script that always renders the visible content of the object and then attach that to the prefab that I'm instantiating? Or something like that?

Here's my world generation script:

 var player : Transform;
 var origin : Transform;
 var width_x : int;
 var width_z : int;
 var depth : int;
 var blocks : GameObject[];
 
 function Start () {
 
  
 
 for(var x : int = 0; x < width_x - 1; x++){
  
     for(var y : int = 0; y > -depth - 1; y--){
     
       for(var z : int = 0; z < width_z - 1; z++){
           
         Instantiate(blocks[Random.Range(0, blocks.Length)], new Vector3(x, y, z), Quaternion.identity);
       
                
          }
          
       }
       
    }
   
 }
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 robertbu · Jul 28, 2014 at 04:39 PM 0
Share

The problem you outline is typically solved by building multiple chunks of mesh, each representing many cubes. Search for Voxels for many posts and information. You can modify the mesh of each of your cubes to eli$$anonymous$$ate the sides not visible, but I doubt that it will give you the speedup you are seeking. A good deal of the overhead is just the number of game objects.

avatar image 432qwerty · Jul 28, 2014 at 04:48 PM 0
Share

Have you considered using Application.LoadLevelAdditive and randomly generating the level in some way, either before the level is loaded or as the level is being loaded? ($$anonymous$$ight not be possible but would probably reduce lag)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Pendrokar · Jul 28, 2014 at 04:45 PM

You write a script that disables MeshRenders for GameObjects which are invisible to the camera/player.

Seems Unity already has something to detect visibility: http://docs.unity3d.com/ScriptReference/Renderer-isVisible.html

I bet the default use of this is to hide MeshRenders when a mesh is out of range for an active camera, not whenever an object without a transparent material is in front of another mesh. But shadows should be an independent element, wonder if they are.

OR

If there is no free space between these blocks/cubes, which there wouldn't be judging from the use of concussive integers in the posted script. Then create a dynamic object, the geometry of which is changed with added or removed blocks/cubes. I bet MineCraft clones have done it this way.

http://docs.unity3d.com/ScriptReference/Mesh.html

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

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

24 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

Related Questions

Create custom objects like in paper.io 2 at runtime 1 Answer

How to move the world/scene not the player - or not? 1 Answer

Confining / Constraining an object transform trajectory to a mesh 1 Answer

Unity adding random transform to mesh components 1 Answer

How can I "generate a mesh" for a projected image or decal? 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