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 MervynArt · Jun 07, 2014 at 10:27 AM · c#static

Will making all variable static reduces the game performance?

Hi, i'm a beginner ,so..... simple answers :D

First of all, i came up with an idea which is to make a whole lot of variables to be static for maybe health purposes or attack counts, mana, etc... so that i can use these variables in other scripts like AI

For example, when the player health is low, i want something like wolf or zombie to search for the player since the player is obviously wounded and blood is spilling out. Thus, i can use the static variable i have declared.

Maybe 1 variable is not much of a impact but what if i declared a whole bunch of them and use them a lot?

Thanks in advance.

Comment
Add comment · Show 3
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 Owen-Reynolds · Jun 07, 2014 at 04:53 PM 3
Share

Little speed stuff isn't even worth worrying about. It's like stopping to pick up a penny when you're late for a job interview.

Think of it as a "which can I program better" decision. If static player vars make more sense to you, you'll write better, faster code with fewer errors.

But, doing it one way for the monsters, and another for the player might be confusing. And the monsters can't have statics for their stats. Using all member vars might help you write better, faster code.

avatar image NickP_2 · Jun 07, 2014 at 05:04 PM 0
Share

It's like stopping to pick up a penny when you're late for a job interview. You made my day!

avatar image Bilelmnasser · Jun 07, 2014 at 05:58 PM 0
Share

this forum must ave like button hahahaha stopping to pick up a penny when you're late for a job interview hahaha

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Bilelmnasser · Jun 07, 2014 at 11:24 AM

in C# : Method of class (function): A call to a static method generates a call instruction in Microsoft intermediate language (MSIL), whereas a call to an instance method generates a callvirt instruction, which also checks for a null object references. However, most of the time the performance difference (static or not) between the two is not significant. Members of class (variables): in term of RAM memory i think static members is better for memory purpose (once the static data member has been defined, it exists even if no objects of its class have been created. Static data members are initialized and destroyed exactly like non-local objects) and check this test between static method and non static method call speed at this page:

http://www.blackwasp.co.uk/SpeedTestStaticInstance.aspx

http://social.msdn.microsoft.com/forums/vstudio/en-US/dd06dc9c-71c7-4fe5-980f-eac81e16b7b1/static-members-performance

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 MervynArt · Jun 08, 2014 at 06:22 PM 1
Share

Thx for your answer :).

$$anonymous$$uch appreciated

avatar image
0

Answer by Jeff-Kesselman · Jun 08, 2014 at 06:42 PM

So, people have answered your question. But let me give you a suggestion.

DON'T

static variables are global variables. Global variables are a leading cause of bugs in computer programs. The more there are, the more likely you are to have a conflict somewhere.

You are going to make yourself a lot of heartache if this program is of any kind of size and you go that route...

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

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

25 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

Related Questions

GameObjects static array NullReferenceException 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

Make my script accessable just by its namespace? 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