• 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 ttibi92 · Feb 22, 2016 at 02:51 PM · freezeinstantiate prefab

Calling Instantiate() freezes the game for 3-5 seconds after build, but not in the editor

Calling the following function for the first time the game freezes for 5 seconds. After the freeze I can call it multiple times and it works fine, until I restart the game, then the problem occurs again. In the editor there is no problem at all.

 void LoadLevelSelect() {
         int HowManyMaps = mapCount;
 
         //currently the value of mapCount is 5 
         //instantiateing blocks in 5 rows and 7 columns

         for (int i = 4; i >= -4; i = i-2) {
             for (int j = -6; j <= 6; j = j+2) {
 
                 if (HowManyMaps != 0) {
                     Vector3 Where = new Vector3 (j, 0, i);
                     Instantiate (MapSelect, Where, MapSelect.transform.rotation);
                     HowManyMaps --;
                 } else
                     break;
             }
         }
 }

Any idea how to solve this little issue? Sorry if there is an answered question for this problem, but i did not find anything useful for this... Thanks in advance

Comment
Add comment · Show 2
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 hexagonius · Feb 22, 2016 at 10:28 PM 0
Share

take a look in the inspector. $$anonymous$$aybe youre spawning something huge which takes long to get loaded into memory. the profiler should tell you cpu spike and or memory increase

avatar image ttibi92 hexagonius · Feb 23, 2016 at 01:08 PM 0
Share

Thanks for the answer I do have CPU spikes caused by GFX.WaitForPresent but they are not so relevant ~5 ms (i guess...) (i'm woring with unity about for 2 months) Anyway i solved it by a pretty lame way... calling it on start and right after destroy everything... Not the best, but it works...

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

48 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

Related Questions

my computer get freeze with itween 0 Answers

CPU Intensive Function, how to call? 1 Answer

Problem with "play" button 0 Answers

Unity freezes after editing code (Visual Studio) 0 Answers

Baking Navmesh at runtime freezes the game for a couple seconds 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