Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by RedBambooLeaf · Oct 20, 2018 at 03:33 PM · inspectorupdateissueupdate problempublic variable

Inspector doesn't show updated values for public variables (ISSUE or IGNORANCE?)

Hi!

I've noticed the inspector is not showing the updated values of public variables in a script. For instance, in my script, the public variable useless is equal to 66:

 public int useless = 66;

  • useless is defined and its value assigned before the Start method of a public class

    • script is saved

    • Unity has compiled

    • No warnings or errors

    It's also a sunny day today


BUT, the inspector, show me this: alt text

It's quite annoying since the effective value in-game is 666 and not the updated 66. If I initialize the variable in the start function everything it's fine but I cannot access and modify quickly public variables using the inspector before hitting play... which is not really useful.

.

I already tried:

  • check auto refresh in edit/preferences/

  • close/open unity and the script editor

  • remove and re-attach the script

  • reset script preset

  • ancient love spells for enchanting modern technology


I don't know if this is actually a Unity issue or just my ignorance regarding Unity, C#, Compilers, and other magical components but I would really appreciate a feedback from this more-helpful-than- Acetylsalicylic-acid community.


Unity Version: 2018.2.3f1 (free, personal) Script Editor: Microsof Visual Studio (15.8) OS: Windows Eyes: brown


immagine.png (813 B)
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
1

Answer by Johandea · Oct 20, 2018 at 03:44 PM

Any variable that are declared as 'public' gets its value from the editor. So if you want to change it you have to do it in the editor or within a method of a script. Just declaring it with another value will not change it. This is the way that it was designed an not an issue, but it takes some time getting used to. Only declare variables as 'public' if you want to be able to adjust them in the editor during runtime.

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 Owen-Reynolds · Oct 21, 2018 at 03:43 PM 1
Share

To follow up, "Inspector wins" is the only way that makes sense. A main purpose of the Inspector is having the variables easily tweakable, without having to open up the code.

The only use of starting values for public variables is when you add the script to something new, to give an initial inspector value.

avatar image RedBambooLeaf · Oct 28, 2018 at 09:52 AM 0
Share

Thank you for your answers, very helpful and clear!

Just for sharing... in Start function:

 public Type x = ( SpecificConditions(x) && setToDefault ) ? x : defaultValueForX;

Allows me to have some extra control over the values modified by the inspector in my script. x will have the inspector assigned value only if the value assigned satisfies certain conditions (SpecificConditions(x)) and there's no intention of having all values set to their default state (setToDefault); else x will be assigned with its default value.

Right in the Inspector I have something like:

 bool setToDefault 

so that "inspector wins" yes, but only if it's allowed to... Which is kinda useful

Cheers and thanks again!

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

161 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Loads of errors after upgrading to 2018.3.0f 0 Answers

How do I bind the value of a public variable from the inspector to some other variable/constant? 0 Answers

Public Variables Not Displaying In The Inspector 1 Answer

Lowpass Exposed Parameter not updating in AudioMixer 0 Answers

Why aren't my scripts updating in my project? 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