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 /
  • Help Room /
avatar image
0
Question by UltraProgrammer · Apr 01, 2018 at 02:51 PM · renderinglagminecraftlaggy

Increase FPS in a block based game

I'm building a game that, at its core, works a bit like Minecraft. Blocks are generated in a terrain that can then be broken to get materials. The similarities pretty much end there, but that's beside the point. For some reason, the FPS on the game is terrible! I added a system that disables the Mesh Renderers after they are a certain distance from the player. With a render distance of 5 units (5 in-game blocks), I was only getting about 20 FPS on my MacBook (Radeon Pro 460 4 GB, 2.7 GHz Intel Core i7) I've changed all shadows to low resolution, and all materials to use the Mobile Diffuse shader (I was told that mobile shaders are less intensive). All of the textures are 1024 X 1024, but after switching them to 1/8 that size, the FPS didn't change. Someone also recommended that I use occlusion culling, but this won't work since the blocks in-game will be broken and placed by the player. After seeing how Minecraft can render millions of blocks without lag, I just don't understand why I can't even render a 5X5X5 area without lag.

Side notes: 1. Almost all scripts on the blocks are removed after generation, so I doubt that is a problem. 2. The "Mesh Render Disable" script uses the Invoke command to run the 'distance to player' check at random intervals. This helps it so the game doesn't have to calculate the distance to the player from all the blocks all at once. (See code below) 3. I tried running the game at lower resolutions, which helped, but not by much. 4. All blocks have a RigidBody, but it is marked as being kinematic. 5. I am aware that Minecraft renders terrain with a chunk based system, but even that is 16X16X16 blocks, which my game struggles with. 6. The max terrain size is 25X25X25 blocks

     using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
 
 public class DeRenderer : MonoBehaviour {
 
     private GameObject Player;
 
     public int RenderDistanceVariable;
 
     // Use this for initialization
     void Start () {
         Player = GameObject.Find("FPSController");
         Invoke("RenderDistanceValueUpdate", 0F);
         Invoke("RenderUpdate", 0F);
     }
 
     // Update is called once per frame
     void RenderUpdate () {
         if (Vector3.Distance(Player.transform.position, gameObject.transform.position) >= RenderDistanceVariable) {
             gameObject.GetComponent<Renderer>().enabled = false;
         } else {
             gameObject.GetComponent<Renderer>().enabled = true;
         }
         Invoke("RenderUpdate", Random.Range(0F, 3.0F));
     }
 
     void RenderDistanceValueUpdate () {
         Player = GameObject.Find("FPSController");
         RenderDistanceVariable = PlayerPrefs.GetInt("RenderDistance");
         Invoke("RenderDistanceValueUpdate", 1.0F);
     }
 }
 

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

0 Replies

· Add your reply
  • Sort: 

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

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

Bad Performance URP 0 Answers

Why is my game lagging for no reason ,Game extremely laggy for no reason 0 Answers

Lags while camera movement (gfx.waitforpresent) 0 Answers

Rendering Game in 2D LAGS!!!! 0 Answers

Major lag when zoomed in close. Any ideas? (android) 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