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 caos23121987 · Nov 24, 2017 at 07:16 AM · fpsprefabsobjectslow polylow fps

To Low FPS. What can I doo.

I've had extreme FPS crashes displaying just 50,000 low-poly cars. I have currently created an EmptyGameObject to which I have assigned a script that places the cars on the screen. Does anyone have any idea how I manage to get everything displayed with an Affordable FPS? This is my Code atm:

 for (int j = 0; j < countOfCars; j++)
     {
         GameObject obj = Instantiate(car) as GameObject;
         obj.SetActive(false);
         autos.Add(obj);
     }
 for (int i = 0; i < autos.Count; i++) 
 {
     if (!autos[i].activeInHierarchy)
     {
         autos[i].transform.position = new Vector3(-10.28f + (currentItemsInRow * abstandSeite), 0.03f, -7.65f + (rows * abstandVorne));
         autos[i].SetActive(true);
         fullCount++;
         Debug.Log(fullCount);
         if (currentItemsInRow >= countInRow)
         {
             currentItemsInRow = 0;
             rows++;
         }
         else 
         {
             currentItemsInRow++;
         }
     }
 }

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

Answer by Blue-Cut · Nov 24, 2017 at 02:17 PM

Hi,

I think your problem is that you add the cars with a synchronous function. You should take a look at Unity Couroutines


In other words, your game crashes because the single frame you use to add 50000 cars needs a lot of time to do its job, when a frame is supposed to display less than a second.


Basically, the idea to fix this would be to add a few cars each update, and then wait for the next Update, until all the cars are added. The solution "looks like" something like this

 private IEnumerator MyRoutine() 
 {
   for(int i = 0; i < nbCarsPerFrame; i++)
   {
     if(nbCarAdded+1 < nbCarsToAdd)
     {
       cars.Add(myCar);
       nbCarAdded++;
     }
   {
   yield return new WaitForEndOfFrame();
 }

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
0

Answer by caos23121987 · Nov 27, 2017 at 11:28 AM

Hello. The game does not crash and the cars are all displayed. Only the FPS crashes into the basement and remains even after all cars have been displayed under 10FPS

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 Blue-Cut · Nov 27, 2017 at 12:06 PM 0
Share

Ok, I didn't get your problem. In that case, I would think to a GPU problem. How do you initialize the materials apply on your cars?

It could be something like you have 1 material instance per car, so Unity doesn't manage to optimize rendering performances.

avatar image caos23121987 · Nov 27, 2017 at 12:20 PM 0
Share

Here is my Code and Screenshot from the Car - Object

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 
 public class cars : $$anonymous$$onoBehaviour {
     // Debug parameters
     public float abstandSeite = 0.25f;
     public float abstandVorne = 0.25f;
     private int fullCount = 0;
 
     private List<GameObject> autos;
     private int rows = 0;
     private int currentItemsInRow = 0;
 
     public GameObject car;
     public float intervall = 0.02f;
     public int countOfCars = 50000;
     public int countInRow = 100;
 
 
     void Start() {
         autos = new List<GameObject>();
 
         for (int j = 0; j < countOfCars; j++)
         {
             GameObject obj = Instantiate(car) as GameObject;
             obj.SetActive(false);
             autos.Add(obj);
         }
 
         InvokeRepeating("createCar", intervall, intervall);
     }
 
     void createCar() {
         if (!autos[i].activeInHierarchy)
         {
             autos[i].transform.position = new Vector3(-10.28f + (currentItemsInRow * abstandSeite), 0.03f, -7.65f + (rows * abstandVorne));
             autos[i].SetActive(true);
 
             // Only for Debug
             fullCount++;
             Debug.Log(fullCount);
 
             if (currentItemsInRow >= countInRow)
             {
                 currentItemsInRow = 0;
                 rows++;
             }
             else 
             {
                 currentItemsInRow++;
             }
             break;
         }
     }
 }

alt text alt text

Thank you for help

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

147 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 avatar image 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

Why such bad fps rate around 2fps 0 Answers

[Help] with WebGL optimization (low poly objects, HD4000 gpu) 0 Answers

How do I select all the items in a prefab? 0 Answers

Instantiate prefab from folder, not scene 0 Answers

Dropped down fps (to 1 or 2 fps) when building standalone ver. of the same project for the same machine with newer unity version. 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