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 billybillyjim · Jun 02, 2014 at 09:31 PM · javascriptglitch

Unity not allowing variables to change unless the name is changed

Hi everyone. Sorry for the long title but I couldn't think of a shorter way to phrase it. Basically, I made a bunch of variables and gave them very large values, and I got an error so I decreased their values to more reasonable ones.

The problem is, they all only output 0 no matter what I assign the variables to anymore. Let's say the variable is called yachtCost. If I type yachtCost = 10; then the game will run and show me that yachtCost = 0. But if I change the name of the variable everywhere in the file to yachtCosts or something, then the change works fine.

I know I can just work around it, but is there some way I can fix unity to allow me to change the values of the original variable names? Thanks.

Comment
Add comment · Show 2
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 tanoshimi · Jun 02, 2014 at 09:35 PM 2
Share

Post your code please, as your question makes little sense.

avatar image Blayer98 · Jun 02, 2014 at 09:45 PM 0
Share

Yeah, We'd need to see your code, We're unable to help you if you haven't posted any type of code.

1 Reply

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

Answer by Graham-Dunnett · Jun 02, 2014 at 09:57 PM

So, public variables in Unity can get their values from one of two places. Firstly, from your script code, secondly from the editor inspector. The inspector is always assumed to be the "correct" source for the value. When you change the variable name, you're telling the inspector there is a completely new variable, and the inspector gets the value from the script. Since changing the name is annoying, just reset the inspector, and it'll re-read the values from the script. Alternatively if you want the values to always be read from the script and never the inspector, make the variables private.

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 billybillyjim · Jun 02, 2014 at 10:33 PM 0
Share

Thank you! Your answer is greatly appreciated! I tried it out and it works!

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

24 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

Related Questions

A node in a childnode? 1 Answer

Climb animation is glitchy and isnt working properly 0 Answers

UnityEngine has no appropriate version problem 1 Answer

Singletons in music script? 2 Answers

2.5D ledge hang with javascript 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