Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 logan4179 · Oct 13, 2018 at 02:06 PM · booleanstaticpausepause gamepausing

Is a global static boolean a good implementation for pausing my game?

Let's say I had a "Game Manager" script as follows:

 public class GM : MonoBehaviour
 {
     public static bool isPaused;
 
     ...blahblahblah
 }

Then, for every instance object in my scene, I had this at the top of it's update

 void Update()
 {
     if (GM.isPaused)
         return;
 
     ...All the rest of the code....
 }

..In addition to that, of course I also set the timescale to 0f upon pausing.

My question is; Is there a substantial reason that using a public, static 'GM.isPaused' variable would be inferior to using a non-static, instance boolean variable? I don't want anyone's personal preference. I want to know, is there some sort of problem/consideration with doing this, however minor (such as lower performance), and how significant is the problem/consideration? You'd be helping me a lot.

Thanks!

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
1

Answer by ElementalVenom · Oct 13, 2018 at 03:26 PM

There is very, VERYYY minor time differences between the two if there are any at all(im talking like nano seconds). The only bad thing about it that i can see is that worst case senereo someone can inject IL(the language that C# is compiled into) into your game to be able to pause the game from the injected code. This is pretty useless in practice though. Ive used public static for game pause variables for the past 4 years and have never ran into an issue with it.

If your game is going to have mods that load assemblies similar to a plugin system it may be an issue. But if you dont understand what this means then your definitely not doing it.

TL;DR: Youre fine using public static for pause variables.

Comment
Add comment · 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
0

Answer by logan4179 · Oct 13, 2018 at 07:00 PM

Thank you for your response. You say you've been using this for the past 4 years, so I'm curious; is this your preferred way of doing it?

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 ElementalVenom · Oct 13, 2018 at 07:02 PM 0
Share

It depends on what im doing. But to be honest: yes, i just use public static bool 80% of the time that I do game pauses lol.

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

95 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

Related Questions

How to Make Pressing a Button Not Trigger Other Events? 1 Answer

Pause game when user pulls down the notification panel 0 Answers

Hold the esc button for a pause menu 1 Answer

Exit play mode with framecount/scripting 1 Answer

[Urgent] When I pause the game, GPU Usage(Task-Manager | Windows) is still the same. How to bring GPU usage close to zero(atleast in empty scene)? 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