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 Wyko · Jun 23, 2011 at 02:32 AM · performancegridcube

Performance While Loading Map

Hey everyone!

I'm trying to figure out why my map takes such an amazingly long time to load. I have Unity Basic, so I can't access any of the diagnostic tools I've heard about. But I just added a simple timer to the load, and it takes about 23 seconds to load. My computer isn't a wimp; what am I doing wrong, and how could I optimize this?

 function InitialGridLoadup (){
     tilePrefab = Resources.LoadAssetAtPath("Assets/Prefabs/Tile/Tile.prefab", Object);
     wallPrefab = Resources.LoadAssetAtPath("Assets/Prefabs/Tile/Wall.prefab", Object);
     ceilingPrefab = Resources.LoadAssetAtPath("Assets/Prefabs/Tile/Ceiling.prefab", Object);
     
     var timeStamp = Time.time;
     Debug.Log(timeStamp);
     
     for ( var x : int = 0; x < mapX; x++ ) {
         for ( var z : int = 0; z < mapZ; z++ ) {
             // Creates the tile
             TileArray[x, z] = new Tile(1, false, 10, x, z);
             Debug.Log(x + ", " + z);
             
         }
         Debug.Log(Time.time - timeStamp);
         yield;
     }
     
     Debug.Log(Time.time - timeStamp);
 }

 class Tile{ 
     var type : int;
     var visible : boolean = false;
     var health : int;
     var x : float;
     var z : float;
 
     
     function Tile(newType, isVisible, newHealth, newX, newZ){//constructor
         this.type = newType;
         this.visible = isVisible;
         this.health = newHealth;
         this.x = newX;
         this.z = newZ;
     }
     
     function Name() : String {return ("Tile" + x + "x" + z);}
 }

Normally, I'd also be adding the following code under the "Creates the tile" comment, which makes it go even slower.

     var tile : Transform = Instantiate(tilePrefab.transform, new Vector3(x,0,z),Quaternion.identity);


To give you an idea of what I'm doing: I'm building a tile-based map from scratch, and I'm trying to build it with good performance in mind.

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
3
Best Answer

Answer by Eric5h5 · Jun 23, 2011 at 03:20 AM

Mostly it's the Debug.Logs that's slowing it down. Take all Debug.Logs out of loops if you want anything like reasonable performance.

Comment
Add comment · Show 4 · 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 Bunny83 · Jun 23, 2011 at 03:40 AM 1
Share

Yeah, it's slow like hell :D

avatar image Wyko · Jun 23, 2011 at 05:17 AM 0
Share

Oh wow... It literally went from 23-35 sec to LESS THAN one second loadup. And that's after rendering. I'm suddenly a lot less concerned about loadup performance! :D

Any idea why it might take two or three seconds after all the grid has been loaded before I can actually move the screen? It freezes for a moment, and all the code has been resolved.

avatar image Eric5h5 · Jun 23, 2011 at 05:50 AM 0
Share

Instantiating thousands of objects is pretty intensive and will take a few moments.

avatar image Dreamora · Jun 24, 2011 at 02:03 AM 0
Share

Short freezes out of the nowhere are normally a consequence of seeing a new texture you never saw before. if that happens it has to be uploaded from RA$$anonymous$$ to VRA$$anonymous$$ for the graphic chip to render it and if you are on desktop this takes from an instant to several to several dozen milliseconds and more depending on texture size, compression and gpu (the worse the gpu the longer, the less its compressed the longer, the larger it is, the longer ;))

avatar image
1

Answer by Dreamora · Jun 23, 2011 at 03:17 AM

how large is mapZ and mapX? depending on that, your code is not even remotely computer and loading friendly, if you exceed what you need to fill the screen there (

Comment
Add comment · Show 3 · 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 Bunny83 · Jun 23, 2011 at 03:42 AM 1
Share

Also if the map size is really big the yield after each row will slow it down a bit more. If you want to provide feedback on the progress it's ok

avatar image Wyko · Jun 23, 2011 at 04:47 AM 0
Share

The objects are just data store to hold the health, position, and type of each tile. That's persistent information that I need from the start. I was thinking of rendering only the visible tiles, sure, but I need to load all the map data and it's taking way too long.

avatar image Wyko · Jun 23, 2011 at 04:54 AM 0
Share

The map is currently 100 by 100. It's size changes at the start of the game depending on what map is loaded.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to instantiate a prefab at mouse pos 1 Answer

Adding Imperfections? 1 Answer

Can't figure out how to achieve an effect like QUBE 1 Answer

Making 3D Objects Stick On Other Objects Like A Grid? 2 Answers

Minecraft style grid and block placement? 2 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