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
1
Question by Dozer · Jun 12, 2010 at 09:39 PM · programmingupdatepreviewrecompilehelloworld

Minor code changes not showing up in preview/run

I have a simple HelloWorld class with the following variable which I pass to GUILayout.Label:

public string message = "Hello World";

If I change the value of the string, it is not reflected when I do a preview or even a full "Build & Run". However, if I change the name of the variable, the modified string will show up from that point on (presumably because a recompilation happened behind the scenes). How can I force this update process to happen without having to trick Unity by renaming a variable?

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 qJake · Jun 12, 2010 at 09:45 PM 0
Share

Unity recompiles all scripts as soon as they are saved, as it "watches" all the files under the Assets folder. You must either not be saving your scripts before compiling, or you have an error in your script(s), which prevents Unity from compiling and saving the current version (it will rollback to the previous working version if there are any script errors).

2 Replies

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

Answer by StephanK · Jun 12, 2010 at 10:28 PM

If you declare a public variable in a MonoBehaviour this will be exposed to the editor so you can change it directly from the inspector rather than in code. As a consequence of this the default value (in your case "hello world") will only be set once you attach the script to a game component. After that the value of the variable is controlled by the editor. So what you could do is remove the component and readd it. The right way however would be to either not decalare the variable public and change it in code, or (better solution) use the editor to change the value.

Comment
Add comment · Show 3 · 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 Dozer · Jun 12, 2010 at 10:38 PM 0
Share

You are exactly right, thank you!

avatar image qJake · Jun 12, 2010 at 11:02 PM 0
Share

Oh, he didn't mention he was trying to edit the variable through code ins$$anonymous$$d of the editor... why are these questions always simpler than they're made out to be? :(

avatar image StephanK · Jun 13, 2010 at 04:09 PM 0
Share

Because that would be too easy. ;)

avatar image
1
Best Answer

Answer by JonManatee · Jun 12, 2010 at 10:31 PM

your problem is most likely that you are changing the value of message in the script. Once the script is attached to an object in a scene, all public variables will be accessible from the editor (assuming that you are not using the System.NonSerialized attribute). To change the variable, do so by selecting the GameObject in the Inspector, and modify the variable there. Or remove the script from the GameObject and then reapply it, and the newly added script will read from the new default value you set in the script.

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

No one has followed this question yet.

Related Questions

Multiple Cars not working 1 Answer

How to update game for happenings while player is away? 0 Answers

Trying to disable the Script below on trigger or the closest thing 0 Answers

Select sprite preview images not showing after upgrading to 2020.2.2f1 3 Answers

Update Preference Item when Preference menu is closed 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