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 /
avatar image
0
Question by MNasser19 · Feb 23, 2018 at 07:45 PM · 2d gamemobilemap-generation

random generated map mobile game frame rate lag

So I'm making a mobile 2D survival game where the map is created randomly when you start a new game. The map is created first as two 2d arrays, one for the tiles and one for the values(for example in the tiles array if the value of tilesArray[30,20] is 1 then the tile will be a grass tile, if it is 2 then it will be a mud tile) after making the arrays, the engine loads the tiles. At the start I tried loading the whole map but it took forever to load and it was insanely laggy. after that I changed it so it only loads the tiles surrounding the player but that dropped the fps because the engine kept instantiating and destroying blocks with every step the player takes in the map. I also tried to make it so there are tiles already loaded and ready but far from the camera and when the player changes the position I change the tiles positions with the player instead of creating new tiles but that didn't fix the lag. what is the best way to load the map?

Ps. Sorry for the long question.

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

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Xarbrough · Feb 23, 2018 at 08:18 PM

Can you post the code? How many tiles are we talking about? I've made a tile-based strategy game for Android and loaded 10,000 tiles at startup without any problems (in a few seconds). I used GameObjects with SpriteRenderers attached and created them in Awake as new objects. Instantiating Prefabs was slightly slower for me, as was loading a scene with already placed prefabs. I assume that Unity's deserialization of a big scene hierarchy is just a little slower than using new GameObject().AddComponent<SpriteRenderer>().

The benefit of the SpriteRenderer is the built-in batching (for render performance), also they are relatively fast to create. However, I assume you have some specific bottleneck in your implementation. Besides posting the code, have you done any profiling with the Unity Profiler so far? It can tell you what exactly takes long. But note, that it doesn't profile anything happening in or before Awake (at least the last time I tried), since the Profiler itself is only initialized in Awake (may have changed since, but if you're not getting results try moving your map loading to Start or later).

Basically, there is no best way of loading a map. You need to check all of your requirements (or list all of them here, if you want to hear opinions), but most importantly you have to profile which part of your code takes too long and then you can optimize it. Often it's just a plain mistake or something obvious to fix to speed it up.

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 MNasser19 · Feb 25, 2018 at 05:37 PM 0
Share

Thank you for the advices. I changed it so it loads using chuncks so it doesn't lag that much. creating new gameObjects ins$$anonymous$$d of instantiating prefabs did make it a little better but I'm going to test it more

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

115 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

Related Questions

Unity - dragging a RigidBody2D Gameobject by mouse/touch without any lag 0 Answers

Making 2d joystick correct to controls (mobile) 0 Answers

Problem with Vector3 Distance and Mouse Input, 1 Answer

simple 2D controller for touch screens (arrows left/right/up/down) 1 Answer

How would I Limit the position of the Z axis Transform? 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