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 ReggieBeRetro · Jul 04, 2016 at 01:45 AM · optimization

24m tri 50m verts from 300 trees

hello.

So i wrote this script to spawn choppable trees from a prefab and finally got it working correctly. Now i am running into problems when trying to optimize the forest of only 300 trees. I checked static in the inspector and it did not help at all I am not saving anything while trying to batch them together. what else can i do to get these numbers down. I am currently getting only 3 to 6 fps when i look at a section of trees.

could it be the tree model that I am using to high of a poly count? 24m triangles and 50m verts are big numbers. ya im getting millions that's not a typo.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class RandomizeObj : MonoBehaviour {
     public Transform obj;
     public Vector3 postiion;
     public GameObject objspawned;
     public int totalobjs;
     public float ObjectsetWidth;
     public float ObjectsetLength;
     public float respawntime = 3600.0f;
     public float respawn = 3600.0f;
     //respawn object if destryed after 60minutes - 3600 Seconds - 3600000.0f milliseconds
 
 
     void Start () {
 
         int spawned = 0;
 
         while (spawned <= totalobjs) {
             Vector3 position = new Vector3 (transform.position.x + Random.value * ObjectsetWidth, transform.position.y, transform.position.z + Random.value * ObjectsetLength);
 
             RaycastHit hit = new RaycastHit ();
 
             if (Physics.Raycast (position, Vector3.down, out hit)) {
 
                 Transform newObj = (Transform) Instantiate (obj, hit.point, Quaternion.identity);
                 newObj.transform.SetParent (transform);
 
                 newObj.name = gameObject.name + "_Obj" + spawned;
             }
             spawned++;
         }
 
 
 
     }
     void Update() {
         respawntime -= Time.deltaTime;
         if (respawntime < 0) {
             CheckForTrees ();
         }
     }
     void CheckForTrees() {
         int i = 0;
         while (i < totalobjs) {
 
             Vector3 position = new Vector3 (transform.position.x + Random.value * ObjectsetWidth, transform.position.y, transform.position.z + Random.value * ObjectsetLength);
 
             objspawned = GameObject.Find(gameObject.name + "_Obj" + i);
 
             if (objspawned == null) {
                 
                 RaycastHit hit = new RaycastHit ();
                 if (Physics.Raycast (position, Vector3.down, out hit)) {
                     Transform newObj = (Transform)Instantiate (obj, hit.point, Quaternion.identity);
                     newObj.transform.SetParent (transform);
 
                     newObj.name = gameObject.name + "_Obj" + i;
                     Debug.Log ("Not Found Object at " + i);
                 } 
             }
 
             i++;
         }
         respawntime = respawn;
 
     }
 }
 
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
0
Best Answer

Answer by ReggieBeRetro · Jul 04, 2016 at 03:35 AM

Oh it is the forest for sure. when i run the game with no trees that is just the terrain and a single player and no other objects instantiated i get 100+fps then as soon as i add them back in and look towards them fps drops. Ill be on the look out for some low poly trees i guess. :/ Or have a crack at making my own low poly trees in blender. I was trying to get away from modeling and focus on getting the majority of the code done but it looks like ill have to spend some time in blender before i can go any farther. thx for the input.

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 KieveKRS · Jul 04, 2016 at 06:56 AM 0
Share

Apologies, I misunderstood the root of your question to be "how do I get my framerate back?" but it seems you've already got that handled. If you're asking for tips on how to optimize your code for smoother results, I'm afraid I'm still somewhat of a newb at the whole C# thing myself (almost a decade since I did any serious coding, and that was college courses).

Something I can suggest would be to replace your "Tree" mesh with a simple cylinder placeholder. That way you can test better iterations of your code without wondering if it's the tree model impacting your framerate. A gain of 10fps in your code might not mean much with a 100+fps scene full of placeholders, but once you start adding real geometry back in, it might make a world of difference.

As for your trees themselves, I'd advise a cap of about 5-7.5k tri on them, and cut your "forest" count in half (150 trees or so). If that seems thin or sparse, you could intersperse your scene with lower-poly models & scrub / brush plants to help fill things out, without overloading the GPU with raw polygons.

avatar image
0

Answer by KieveKRS · Jul 04, 2016 at 03:19 AM

That's 80,000 tri per tree. To put things in perspective, character models are typically the most complex geometry a game will handle and a quick search suggests AAA-models for recent games range between 10-40k. Keeping in mind, we're talking main characters, which the game is only expected to render a couple of at any given time.

So yes, it's extremely likely that a forest of 80k-tri trees is killing your framerate. If they're your model, consider some heavy optimization. If not, I might suggest looking for a substantially lighter mesh.

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

60 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

Related Questions

Failed to Initialize 3D Graphics? 10 Answers

Dynamic Batching for SpritesRender 2 Answers

Anyway to check if a tree is billboard? Script to know if a tree is billboard? 0 Answers

Should i have a script for every button? 2 Answers

Sprite size much bigger than originally - how to resolve 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