Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Romejanic · Feb 11, 2015 at 08:51 AM · buglagpauseoverhead

Problems with "Overhead"

I am having a problem with my game. The game runs pretty smoothly most of the time. That is, until you pause it. Whenever I paused the game, one of my cloths would disappear and there is incredible lag. I originally blamed it on the cloths, so I disabled them and replaced them with a plane renderer. But the problem persisted, so I opened the profiler and I found this:

alt text

I have looked around on Google and Unity Answers and I cannot find anything that has helped me. Everyone else is having the problem when first starting the game. I am only having it when I pause the game. The beginning of the red spike is where I pressed Esc and paused the game.

Here is my pause code:

 using UnityEngine;
 using System.Collections;
 
 public class PauseMenu : MonoBehaviour {
 
     public bool isPaused = false;
     public bool canPause = true;
 
     public Font font;
 
     void OnGUI() {
 
         if(!isPaused) {
 
             return;
 
         }
 
         GUIStyle style = new GUIStyle();
         style.font = font;
         style.fontSize = 50;
         style.normal.textColor = Color.white;
 
         GuiUtils.drawLabelWithShadow(new Rect(10, 10, 200, 200), "Paused", style);
         style.fontSize = 25;
 
         if(GUI.Button(new Rect(10, 250, 100, 50), "Resume", style)) {
 
             isPaused = false;
 
         }
 
     }
 
     void Update () {
     
         Time.timeScale = isPaused ? 0f : 1f;
         Camera.main.GetComponent<BlurEffect>().enabled = isPaused;
 
         if(Input.GetKeyDown(KeyCode.Escape)) {
 
             isPaused = !isPaused;
 
         }
 
         if(!canPause) {
 
             isPaused = false;
 
         }
 
         foreach(Animation animation in (Animation[])GameObject.FindObjectsOfType(typeof(Animation))) {
 
             animation.enabled = !isPaused;
 
         }
 
     }
 
     public static PauseMenu getPauseMenuInstance() {
     
         return (PauseMenu)GameObject.FindObjectOfType(typeof(PauseMenu));
 
     }
 
 }
 

Can anyone help me? I've been having this problem for a while, so any help would be greatly appreciated! I have made pause menus in the past that work the EXACT same way as this one, but I've never encountered this problem.

Thank you! Romejanic

unity-profiler-1.png (101.4 kB)
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 copperfeld · Feb 11, 2015 at 09:46 AM

hope this helps: first i noticed the FindObjectsOfType() method. Better not use expensive finder calls in an Update method, which is called once per frame. But that is probably not the (only) reason for your drag in pause mode.

'GUIStyle style = new GUIStyle();' -> also, I'd rather avoid to create new objects on each call of 'OnGUI', because it's again expensive and makes the garbage collector running, which will slow down your game most likely.

I recommend you to do both things ahead and see if it helps; move them into Start() or Awake() methods, for instance.

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 Romejanic · Feb 17, 2015 at 04:08 AM 0
Share

Thank you so much! I moved the GUIStyle into a variable but I still had problems, so I moved all of the stuff that stayed static (font, text color, etc) into Start() and it works perfectly! I think it even took load off of the game anyway! You are the best, thank you so much!

avatar image Romejanic · Feb 17, 2015 at 04:12 AM 0
Share

On my 27" i$$anonymous$$ac, the title screen runs at 2000fps ^-^

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Overhead spike of 46.2ms when profiling on Android!!! 1 Answer

Game freezes when i press play but when i press Esc it starts 0 Answers

Gfx.WaitForPresent is limiting fps to 30-45 with Application.targetFrameRate = 60; 1 Answer

Unity UI operation stutter in Windows 7, Aero is disabled 1 Answer

4.6.0 to 4.6.1 makes player lag, bug? 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