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 pcdrive · Jan 06, 2018 at 10:33 AM · android2d game3d modelslow fps

3d objects make games run slower?

Hi everyone!


My problem is, that i want to make a 2D android game, and if i use 3D Objects in it cause it looks far better in top down view, the game gets low on fps.


To describe it in detail:

I have a 10x10 map. Each element is a 3D game object. some of them is floor element (simple cube with texture) and some of them is wall (some wall model i created). And even if only 5-7 is enabled at once which is in the sight range the game gets down to 17-21 fps. Without them it runs easy on 60 fps. Does android hates 3D models? Or cellphones are too weak to render them? After 2 days of searches i don't even know what to think.


Hint: I tried to replace both the walls, and the floor elements, to default texture-less cubes (the default white cubes) and it also make the game slow to the same 17-21 fps.


I dont think that its relevant, but here is some code i use to create and store objects:

     public float CamSightRange;
     public GameObject Wall;
     public GameObject[] Floor;
     public GameObject Gate;
     public GameObject Camera;
     public GameObject Player;
 
     private GameObject[] Elements;
     private int[] map;
 
     private GameObject Walls;
     private GameObject Floors;
 
     // Use this for initialization
     void Start ()
     {
         Walls = new GameObject("Walls");
         Floors = new GameObject("Floors");
 
         Walls.transform.parent = transform;
         Floors.transform.parent = transform;
 
         GenerateArray();
 
         GenerateMap();
 
     }
 
 ...
  // i generate some 10x10 map as 1D [100] int array in the GenerateArray method
 ...
 
     private void GenerateMap()
     {
         Elements = new GameObject[102];
 
         for (int i = 0; i < 100; i++)
         {
 
             if (map[i] == 0)
             {
                 Elements[i] = GameObject.Instantiate(Wall, new Vector3(i % 10 * 10 + i * 0.002f, -i / 10 * 10, -0.6f + i * 0.001f), Quaternion.LookRotation(Vector3.back));
                 Elements[i].transform.parent = Walls.transform;
                 Elements[i].transform.Rotate (new Vector3(0,0,(Random.Range(0,4))*90));
             } else 
             if (map[i] == 1)
             {
                   Elements[i] = GameObject.Instantiate(Floor[Random.Range(0,Floor.Length)], transform);
                   Elements[i].transform.position = new Vector3(i % 10 * 10, -i / 10 * 10, 0);
                   Elements[i].transform.Rotate(new Vector3(0, 0, (Random.Range(0, 4)) * 90));
                   Elements[i].transform.parent = Floors.transform;
             }
             else
             if (map[i] == 2)
             {
                 Elements[i] = GameObject.Instantiate(Gate, transform);
                 Elements[i].transform.position = new Vector3(i % 10 * 10, -i / 10 * 10, -0.502f);
                 Elements[i].transform.parent = transform;
             }
         }
 
         Elements[100] = GameObject.Instantiate(Player, transform);
         Elements[100].transform.position = new Vector3(lastpos % 10 * 10, -lastpos / 10 * 10-3, -1);
         Elements[100].transform.parent = transform;
 
         Elements[101] = GameObject.Instantiate(Camera, transform);
         Elements[101].transform.position = new Vector3(lastpos % 10 * 10, -lastpos / 10 * 10 - 3, -3);
         Elements[101].transform.parent = transform;
         Elements[101].GetComponent<Camera>().target = Elements[100];
     }



the parent objects are some empty gameobject which help me to distribute different types of objects.

Comment
Add comment · Show 1
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 pcdrive · Jan 09, 2018 at 06:19 PM 0
Share

additional information: If i use sprites ins$$anonymous$$d of the 3d objects it easily works in 60 fps

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by OneCept-Games · Jan 06, 2018 at 10:52 AM

1: What do you do in your Update() callback? Sometimes, if you do heavy loops, instantiating of objects etc. it will cause FPS decrease.
2: Are your 3D objects simple cubes, or are they complex models with high amount of vertices?
3: Are your textures 2048x2048 or higher, 512x512 should be enough

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 pcdrive · Jan 06, 2018 at 02:37 PM 0
Share

1, nothing is called if the player did not moved. If moved the update just enable or disables the object in sightrange. The problem exists when no movement happened so it is not problem.


2, Simple cubes, but the strange thing is, that if i use my models ins$$anonymous$$d of cubes same fps will be shown. (my models are about 20-30 vertices max. so i dont think its more complicated than cubes....)


3, i just compressed my textures to 512x512... so its not problem too...

avatar image
0

Answer by meat5000 · Jan 06, 2018 at 02:59 PM

At a glance... as you have heavy usage of Start() which causes a delay to any functions/callbacks such as Update() within the same scripts. You routine looks pretty intensive, perhaps consider spreading out the operations with a coroutine and switching out Instantiation for Object Pooling which will massively help with the Garbage Collection. When a large amount of objects have been Instantiated then destroyed the GC kicks in when it feels like, to clear the mess. This process completely delays the program until the operation is complete. With a moderate amount of objects the delay can be in the order of 100-200ms per time which will obviously destroy your game even if this happened once every 5 minutes, from a user experience point of view.

If you have a heavy amount of objects that constitute the gameworld then using voxels would help. Make sure Object batching is in effect.

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 pcdrive · Jan 06, 2018 at 08:43 PM 0
Share

Actually i shredded almost 80% of the code, since im almost done with the game base. i have enemies, maps, statistics... And based on the device tests nothing wrong with the functions. start method use less then 0.1 second to count even on my phone.. which is pretty much the target. my only problem is the fps drop caused by the objects... if i find a solution to this problem im about a week or two from publishing

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

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

How can I make an object point to a touch while pressing other buttons (2D for android) 1 Answer

High memory usage 2d game 1 Answer

Keeping true color of 3d objects in Unity 1 Answer

Android double jump 0 Answers

Android not rendering Unity Objects (pink) 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