x


Clearing Cached Variable

Hello,

I have been testing scripts that I am working on, in the most recent version of Unity on a 64 bit Windows 7 machine. When I assign a variable the first time, then run the code everything is hunky dory. If I change the amount of the variable and run the code again, very often the variable will not be updated. To get the code to run with the updated variable, I have to rename all the variables with the find and replace tool. I've tried restarting the application, and even rebooting the machine when this issue arise. I was wondering if anyone else was having this same problem and if a solution has been discovered.

Best Regards,

Steve

more ▼

asked Jun 22 '11 at 12:35 AM

Grasshorse gravatar image

Grasshorse
16 9 10 11

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Serialised variables (those that appear in the inspector) will keep their values from the inspector even if you change the code. Your options are:

  1. Add System.NonSerialized attribute to them, or
  2. Mark the variables private if no other class needs to access them, or
  3. Right click in inspector and revert the value.

In general, choose carefully what you want to set from code and what from the inspector.

more ▼

answered Jun 22 '11 at 12:42 AM

Waz gravatar image

Waz
6.5k 23 33 71

Thanks Warwick,

That did the trick. I was trying to "wait" to get too specific by marking them private, static, etc. I guess I need to stop doing that. :) Thanks again for your help!

Best Regards, Steve

Jun 22 '11 at 12:51 AM Grasshorse
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x850
x77
x58
x31

asked: Jun 22 '11 at 12:35 AM

Seen: 742 times

Last Updated: Jun 22 '11 at 05:10 AM