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 /
avatar image
1
Question by Micha Lewtak 2 · Feb 01, 2010 at 07:36 PM · editorjavascript-specific

How to prevent script instances from overriding default global variables set in the script?

Without making all the variables private and then having to make tons of Get functions, and switch the inspector to debug mode to view values during gameplay. If I save a new value in a script, Unity should update all script instances. Especially if it's just one. How to make the scripts static somehow? It's gonna be one script instance per each script anyway (main player object with a few scripts here and there).

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 cregox · Feb 24, 2010 at 12:45 AM 0
Share

I'm confused. Can you provide an example?

4 Replies

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

Answer by Ehren · Feb 25, 2010 at 08:55 PM

You could set the values of your member variables in Awake().

var foo : float;

function Awake(){ // Ignore inspector setting and use scripted value instead. foo = 4.0; }

Comment
Add comment · Show 1 · 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 cregox · Feb 26, 2010 at 01:09 PM 0
Share

d'oh. Yeah, and then, after all I said, there's that! :P

avatar image
1

Answer by Tetrad · May 16, 2010 at 05:54 AM

What you want are public member variables for script access but you don't want the editor to access them.

There's a built in way to do this, just set the attribute HideInInspector.

http://unity3d.com/support/documentation/ScriptReference/HideInInspector.html

For Javascript you'd just preface the variable with @HideInInspector. In C# you'd prefix it with [HideInInspector]. (Granted, in C# you'd probably use properties instead of public variables.)

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

Answer by Joe Wreschnig · Feb 01, 2010 at 11:53 PM

Why set/change a value in the script at all? Just set it only in the Inspector.

Comment
Add comment · Show 1 · 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 Micha Lewtak 2 · Feb 02, 2010 at 05:33 PM 0
Share

Because. It's faster for me.

avatar image
0

Answer by cregox · Feb 25, 2010 at 08:03 PM

The question body is too confuse. So I'll answer just the title.

In csharp, simply use internal instead of public:

 public bool aPublicBool = true; // you may change this in the inspector
 internal string likeAPublic = "ok"; // can only be seen on the Debug inspector


old answer

If you set the value for a variable on the script and outside any function, those variables that will be available on, that's the default value. When you add the script to some object, it will use those values.

When you do that, the instanced script will be saved in the project with those values. So, if you later change the script default values, the old ones will persist.

If I understand right, you want to override this setting. I highly doubt there's any simple way to do that.

But you can set all variables to private, save the script so the inspector will remove the variables, then set it back and save the script again. No need to create get functions at all.

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

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

How to make tab in editor near the top? 1 Answer

Are any UnityEditor Classes available at runtime (outside of the editor)? 1 Answer

How can "bounds" for script variables be defined for use in the Inspector? 2 Answers

Textmate - features: shortscuts for c#, javascript, shaderlab? 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