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 /
This question was closed Aug 23, 2018 at 08:27 PM by $$anonymous$$ for the following reason:

The question is answered, right answer was accepted

avatar image
-1
Question by $$anonymous$$ · Aug 22, 2018 at 08:06 PM · minecraftblockcpu usage

How can I reduce CPU cost of blocks in my Minecraft clone?

Hi, so I'm making a game like Minecraft because blocks are easy to work with, but the physical part of the block seems to take up way too much CPU. What I mean by physical is empty gameObject containing six quads and a box collider, rather than the type I made called 'Block" which can't be seen. I'm going to make it so that only exposed blocks are active, but there could easily be tens of thousands of exposed blocks active at a time, and my game starts to lag with only 5,000 of them. I don't know how Minecraft allows so many blocks onscreen at once without lagging, but I'd like to accomplish the same.

EDIT: Okay so I've found an even bigger problem. When I run a check Update for every block to see if I can disable it for better performance, it actually seems to be using even more of the CPU than if I didn't run the check and just left it active, which is not looking good. What I'm doing is checking every side of a block for an empty space, and then set the block active once it finds an empty space, or set it inactive if it doesn't find one. How does every other block-based game accomplish updating all the blocks without lagging due to the potential of millions of blocks?

                 //This code will run for every block.
                 if (blocks [x, y, z] != null) {
                     if (x + 1 < width) {
                         if (blocks [x + 1, y, z] == null) {
                             Enable (physicalBlocks [x, y, z]);
                             break;
                         }
                     }
                     if (x - 1 >= 0) {
                         if (blocks [x - 1, y, z] == null) {
                             Enable (physicalBlocks [x, y, z]);
                             break;
                         }
                     }
                     if (y + 1 < height) {
                         if (blocks [x, y + 1, z] == null) {
                             Enable (physicalBlocks [x, y, z]);
                             break;
                         }
                     }
                     if (y - 1 >= 0) {
                         if (blocks [x, y - 1, z] == null) {
                             Enable (physicalBlocks [x, y, z]);
                             break;
                         }
                     }
                     if (z + 1 < length) {
                         if (blocks [x, y, z + 1] == null) {
                             Enable (physicalBlocks [x, y, z]);
                             break;
                         }
                     }
                     if (z - 1 >= 0) {
                         if (blocks [x, y, z - 1] == null) {
                             Enable (physicalBlocks [x, y, z]);
                             break;
                         }
                     }
                     if (physicalBlocks [x, y, z].activeSelf) {
                         Disable (physicalBlocks [x, y, z]);
                     }
                 }
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

  • Sort: 
avatar image
3
Best Answer

Answer by Bunny83 · Aug 22, 2018 at 11:01 PM

Sorry but there are already way too many minecraft related questions here on UnityAnswers

  • https://answers.unity.com/questions/56121/minecraft-style-grid-and-block-placement.html

  • https://answers.unity.com/questions/623541/minecraft-style-block-placement.html

  • https://answers.unity.com/questions/506349/build-system-for-minecraft-lookalike-game.html

  • https://answers.unity.com/questions/700004/block-lightning-minecraft-like.html

  • https://answers.unity.com/questions/392185/how-do-i-make-cube-grid-like-minecraft.html

  • https://answers.unity.com/questions/1126340/which-voxel-terrain-solutions-exist-for-unity.html

  • https://answers.unity.com/questions/177931/tutorial-minecraft-chunks.html

  • https://answers.unity.com/questions/1477652/minecraft-style-culling.html

  • https://answers.unity.com/questions/254523/minecraft-rendering.html

There are also many forum posts on that topic:

  • https://forum.unity.com/threads/minecraft-style-game.177831/

  • https://forum.unity.com/threads/tutorial-procedural-meshes-and-voxel-terrain-c.198651/

  • https://forum.unity.com/threads/minepackage-minecraft-starter-package.69573/

And also other resources

  • http://forum.brackeys.com/thread/unitycraft-lets-make-a-minecraft-style-game/

People got already so bored with that subject they already done minecraft in one day challanges.

Minecraft is not an easy made game. Minecraft requires several advanced techniques you have to master. It looks like you don't really have done much research for your project.


ps: In Minecraft you don't see several 10k blocks at once but millions. Without chunking the world this is impossible to handle.

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 $$anonymous$$ · Aug 23, 2018 at 01:18 AM 0
Share

What is this "chunking of the world"? anyhoo, I just realized that I shouldn't be updating every block every frame, but am ins$$anonymous$$d going to only update them when something happens to them. Also, I found that I should be storing the blocks internally simply as data, and only create physical blocks when needed, and delete them otherwise. I know that there are millions of blocks at once in $$anonymous$$increaft, but I was just referring to their physical representations (graphics). Thanks for all the links, this question was mostly just about increasing performance.

Follow this Question

Answers Answers and Comments

87 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 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 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

Minecraft block placing/ block building - how to? 2 Answers

Delete Blocks 1 Answer

(script) how to get terrain to turn into blocks 0 Answers

map generation issues 0 Answers

This script really makes my game lag! 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