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
3
Question by Dreoh · Apr 05, 2012 at 02:58 PM · static

What exactly is static?

I know its not necessarily a Unity question, but I've googled a bit what static is, but can't find an explanation that I can easily comprehend..

anyone got an explanation on static variables in layman's terms?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
10
Best Answer

Answer by Statement · Apr 05, 2012 at 03:39 PM

In laymans terms:

  • There exists only one copy of a variable if it's static (accessed through the class type).

  • There can be many copies of a variable if it's not static (accessed through an object reference).

Static variables are said to belong to the "class" and non-static (member variables) are said to be long to an "object" (an instance of a class type). Since there is only one class, there is only one static variable. Since there can be many objects of a class, there can be many member variables.

When I said there exist only one copy of the static variable, I did not mean to say that the value it holds is unique, it's only the symbol that is unique.

There are special cases to static variables where they can be unique per thread, but the default behaviour is unique per assembly.

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 Dreoh · Apr 05, 2012 at 04:00 PM 0
Share

Thank you!

avatar image
7

Answer by fafase · Apr 05, 2012 at 03:19 PM

Static means that the variable belongs to the class and not the object (in Unity).

That means that only one instance of it will be created and will remain over any scope.

For example, your enemy class would have a static enemyCount; This variable will be the same for all enemies as there will be only one instance of it. Shall you destroy an enemy object or all of them, the variable is still there, if you create a new object then he will access that same variable.

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 Bunny83 · Apr 05, 2012 at 03:31 PM 0
Share

This is true, but don't mix up scope and extent

avatar image Dreoh · Apr 05, 2012 at 04:00 PM 0
Share

Thank you!

avatar image
5

Answer by Kryptos · Apr 05, 2012 at 03:01 PM

Wikipedia: Static variable

MSDN: Static Classes and Static Class Members (C# Programming Guide)

A static method, field, property, or event is callable on a class even when no instance of the class has been created.

In other words, static properties or methods are shared by all instance of a class. Whereas member properties and methods belongs to a particular instance of the class.

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 Dreoh · Apr 05, 2012 at 04:00 PM 0
Share

Thank you!

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GetInstanceID ?????? 2 Answers

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

Accessing another var on another script 1 Answer

Play audio on keyboard click? 1 Answer

How to emit particle from a collision? 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