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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Odinnorn · Jan 22, 2014 at 06:50 PM · variableclassstaticjava

Static Class unmodifiable variable

Wow, wording the questing was more difficult then I thought.

Hello, I have a problem I've been trying to figure out for some time now. Couldn't find any answers both here and on Google ( I usually manage to solve my own problems). But now I seem to have landed in a bottomless pit.

This is my first question and I'm quite the newbie so be gentle ;) Anyways, the problem!

I have a problem with a static class I'm using in my game. It's a class that holds stats for different characters. It has been working for the longest time so while testing I raised some of the stats temporarily. The problem occurred when I tried to change the stats back to normal. No errors show up but in-game the numbers(of the stats) won't change, they're stuck with the temporary numbers, as if I'm unable to modify them.

Here is the kicker though. I have other static classes that work perfectly, I'm able to modify the numbers in the script without any problems. There are even variables within the script that's giving me problems which work. It's just that one variable within that one static class.

I have no idea how to fix this!

Here is the code from the script that giving me problems: #pragma strict

  static class HeroClass extends MonoBehaviour {
 
     
     public class Stats {
         
         //Basic stats
         var Name:String;
         var Strength:int;
         var Smart:int;
         var Speed:int;
         var Luck:int;
         
 
         //constructor for stats
         public function Stats(NAME : String, STR : int, INT : int, SPEED : int, LUCK : int) {
             Name = NAME;
             Strength = STR;
             Smart = INT;
             Speed = SPEED;
             Luck = LUCK;
         }
         
         
 
     }
     
     //Stats for different heroes
     public var HeroDStats : Stats = new Stats("HeroDeedee", 15, 15, 15, 15); //15
 
     public var TinaStats : Stats = new Stats("Tina", 14, 20, 17, 14); //THIS IS BROKEN FOR SOME REASON
     
     
 }


It's only TinaStats that's broken. I'm able to edit the numbers freely for HeroDStats then for example using print(HeroClass.HeroDStats.Name) works perfectly but if I edit TinaStats then use print(HeroClass.TinaStats.Name) it only gives me the temporary input.

It's probably something pretty obvious but I'm stumped! Please let me know if there are any details I'm missing.

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
0
Best Answer

Answer by Odinnorn · Jan 23, 2014 at 12:19 PM

Doesn't matter anymore. Figured it out myself. I had: var otherScript = GetComponent(HeroClass).TinaStats; in another script. This for some reason was blocking any modification of TinaStats in the class.

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

18 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

Related Questions

[C#] Is there a way to call static variables directly, independent from parent class? 3 Answers

Global Variables Refuse to Cooperate 1 Answer

How to build up the class structure for an object 1 Answer

GUI.DrawTexture Error & Static Variables!! 2 Answers

Couroutines not working in static class 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