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 Essential · Nov 04, 2013 at 12:15 AM · bugvariablepublicprivate

Changing variable values not having any effect

 class RainManager extends MonoBehaviour 
 {
     static var instance : RainManager;
     @HideInInspector var groundPos : float = -1.5;
     @HideInInspector var particleNum : int = 250;
     @HideInInspector var areaSize : float = 13.0;
     @HideInInspector var areaHeight : float = 5.0;
     @HideInInspector var fallingSpeed : float= 22.0;
     @HideInInspector var particleSize : float = 0.4;
     @HideInInspector var flakeRandom : float = 0.1;
 
 
     public function Awake ()
     {
         instance = this;
         // Always prints the same thing, regardless of the above values...
         Debug.Log( particleSize + " // " + particleNum );
     }
 }

The above variables were originally public, so they showed in the inspector, but I later changed them to @HideInInspector. But now modifying the values in the script doesn't have any effect. I think the previous inspector values are overwriting the script values? How can I reset the inspector so it's not overwriting the data? I've already tried a few things several times…

  • Clicking the cog and selecting "Reset"

  • Changing the vars to private, letting the script compile, and then switching back to @HideInInspector

  • Removing the vars, recompiling, and replacing the vars

  • Deleting the gameObject and creating a new one and attaching the new script

Whenever I do these things, the values are set back to whatever is in the script, but as soon as I change the values they refuse to make any further changes.

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

Answer by Essential · Nov 04, 2013 at 03:48 AM

Replacing @HideInInspector with @System.NonSerialized fixed the issue.

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 Eric5h5 · Nov 04, 2013 at 01:00 AM

Public variables always get their values from the inspector. Unity would break horribly if it ever worked any other way. If you only want variables to get their values from the script, don't make them public.

Comment
Add comment · Show 12 · 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 Essential · Nov 04, 2013 at 01:03 AM 0
Share

is declaring a default var, e.g. — var myVariable = 0.0 — does that make it public? How do I make it private but still accessible from other scripts?

avatar image Eric5h5 · Nov 04, 2013 at 01:12 AM 0
Share

The default for Unityscript is public, so "`var myVariable`" is public. Typically you use properties (getters/setters) for variables that are accessed from other classes.

avatar image Essential · Nov 04, 2013 at 01:14 AM 0
Share

Oh… I was just following the advice of some dude named Eric5h5: http://answers.unity3d.com/questions/21043/stupid-question-about-public-private-variables.html

avatar image Eric5h5 · Nov 04, 2013 at 01:22 AM 0
Share

That was from 2010...Unityscript didn't have properties back then (or if it did, it was undocumented). Although $$anonymous$$ike 3's answer on that page amounts to more or less the same thing, even if it's not quite as convenient.

avatar image Essential · Nov 04, 2013 at 01:42 AM 0
Share

Wow, I haven't even heard about this before. Everything I've ever read said to use @HideInInspector. I'm trying to google information about how to get / set variables in other scripts, and as far as I understand, it works essentially like accessing a static variable, but for private variables? Unfortunately it seems heavily un-documented. Almost everything I can find results with an, "It's not working". Can you give me a basic example Eric?

Show more comments

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

16 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

Related Questions

When to use private var. and public var.? 4 Answers

C# - public variable not exposed to the Project Panel? (n00b to c#) 1 Answer

[C#] Assets/BreakObject.cs(20,62): error CS0165: Use of unassigned local variable `broken' 1 Answer

When to use public or private variables for the inspector? 2 Answers

Share Public Classes 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