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
6
Question by vinnyhassell · Aug 28, 2014 at 01:46 PM · inspectorupdatevalueproperty

Public variable in script doesn't update in Unity inspector when saved

I'm new to Unity and am trying to build a very basic script. I have a property in a game control script like so:

 public float objectSpeed =0.1f;

If I save this script and attach it to an empty game control object, I can now see the script attached in the inspector showing the property, which is called Object Speed:

alt text

But if I change the value of objectSpeed in the script and save the script, it doesn't update the value in the inspector in Unity, meaning that when my script runs, it picks up the value from within Unity, and not the updated value in the actual script.

I've tried saving the script, restarting Mono and Unity, and the original value never changes. However if I remove and re-attach the game control script to the game control object, the value now successfully updates in the Unity inspector.

I'm not sure what is going on here and this has caused me some confusion. Is this a bug or am I doing something daft? I'm using Unity version 4.5.2f1.

unity.jpg (7.8 kB)
Comment
Add comment · Show 1
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 contab009 · Aug 28, 2014 at 01:48 PM 0
Share

I'm also experiencing this (or at least something similar). $$anonymous$$y workaround is that when I hit Play, I stop and hit it again and it finally updates.

1 Reply

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

Answer by Landern · Aug 28, 2014 at 01:47 PM

If it was already attached in scene or on prefab, the serialized value originally in the inspector gets saved. If you want to reset the component to the script default values, click the little cog(gear) and reset the component.

Comment
Add comment · Show 6 · 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 vinnyhassell · Aug 28, 2014 at 01:50 PM 0
Share

Ah yes that fixes it. Caught me right out, useful to know! Thank you!

avatar image dyllandry · Jun 23, 2016 at 03:25 AM 1
Share

Is there a better way to do this? Lets say in the case of myself having 10 of these objects that won't update?

avatar image jdean300 dyllandry · Jun 23, 2016 at 08:07 AM 0
Share

Couldn't you just ctrl+click the ten different objects and set their values in the inspector all at once? Alternatively, you could try to comment out the variable in your script and all of it's usages, save the scene, then remove the comments.

avatar image brutecold jdean300 · Jun 29, 2016 at 11:01 AM 1
Share

Yes if they all have the same script you could, but still if you have lots of objects, and a few different scripts that need some number to change this could be really annoying.

also resetting the script remove other things you might have added to it so you will need to add again anything you have on that script (like game objects).

It would really be the best if changing the script actually changed it on everything.

Show more comments
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

7 People are following this question.

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

Related Questions

How to get a value set by another script? 0 Answers

Text in the scene is not being updated! 0 Answers

what's wrong with unity 1 Answer

How do I add a tool tip for class variables in the inspector? 1 Answer

Specifying script through inspector 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