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 Fattie · May 18, 2012 at 07:59 AM · bugsreimport

Bizarre "script changes not changing anything" issue ???

This problem totally explained by Bunny, see below...


Have a variable with a string, like

 public var message : String = "some text here";

Arrange to show it on the screen. Hit Play. Now, using your text editor change the text of the variable.

 public var message : String = "some text here - edited";

When I hit play again, it simply does not change -- Unity still seems to "know" only about the previous text.

A total mystery to me, any explanation?

bizarre.gif (92.0 kB)
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
4
Best Answer

Answer by Bunny83 · May 18, 2012 at 10:43 AM

That's not a bizarre behaviour... Unity will serialize all public variables of your scripts so you can edit the values in the inspector. If you don't want the variable to be serialized, use the NonSerialized attribute.

copied from comment
You can simply reset your instance by right-clicking at the components header and select Reset. This will erase all serialized data and re initialize the component. If your script has a Reset function, it will be called in this case. Reset is also called for newly added components.

Generally there are 4 types of variables (i've omitted static and protected):

Serialized variables:

 public var var1 : String = "text1";  // the public keyword can be omitted in UnityScript
 
 @System.SerializeField
 private var var2 : String = "text2";

Non serialized variables:

 @System.NonSerialized
 public var var3 : String = "text1";  // the public keyword can be omitted in UnityScript
 
 private var var4 : String = "text2";

The confusing thing is maybe that Unity automatically serializes public variables.

Another way is to initialize your variables in Start(). Start is called after the component has been initialized.

 public var var5 : String;
 
 function Start()
 {
     var5 = "text5";
 }

Here're the same examples in C#

Serialized variables:

 public string var1 = "text1";
 
 [System.SerializeField]
 private string var2 = "text2";  // the private keyword can be omitted in C#
 

Non serialized variables:

 [System.NonSerialized]
 public string var1 = "text1";
 
 private string var2 = "text2";  // the private keyword can be omitted in C#


 public string var5;
 
 void Start()
 {
     var5 = "text5";
 }
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to import the object from server to unity 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Material doesn't have a color property '_Color' 4 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