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 maninduw · Jan 12, 2014 at 12:52 PM · inspectorvariables

Do I have to change the value of a pubilic variable in the script even if I have already changed the value in the inspector variable?

I have attached a script to a game object in order to move it. A public variable of type Vector2 is defined to set the speed and values 50 and 0 are given. Now I have a field to set the speed in the inspector. If I change the value from the inspector instead of editing the script, Do I have to change the value in the script when I am going to build the project?

Thank you

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by ankush_Kushwaha · Jan 12, 2014 at 01:37 PM

No, You don't need to change it in your script. Unity3d prefer the value given in 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 maninduw · Jan 12, 2014 at 01:55 PM 0
Share

Thank you very much.

avatar image
1

Answer by frarees · Jan 12, 2014 at 01:09 PM

The values set in the inspector will always prevail to the directly defined in your script. That means, that if you do:

 public Vector2 myVec = new Vector2 (50f, 0f);

That value will be overridden by the one found at inspector (that's because of Unity's internal deserialization). However, if you set that value on the proper Unity callback e.g. Awake, Start, OnEnable... the values found on those methods will be the final values to be used. AFAIK Unity deserialization occurs between script's constructor and OnEnable callback.

Comment
Add comment · Show 2 · 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 KellyThomas · Jan 12, 2014 at 01:16 PM 0
Share

Another point to note is that if the script is attached to another object, that other object will start off with the default values as defined in the script.

avatar image maninduw · Jan 12, 2014 at 01:54 PM 0
Share

Thank you very much for the explanations.

avatar image
0

Answer by Owen-Reynolds · Jan 13, 2014 at 12:13 AM

As per the KellyThomas comment above, the value in your script should be the "normal" value for that type of object. If you will only ever make one (like all bullets in the game are identical,) it won't matter.

Say you will be making lots of monsters, and 8 is a good walk speed. Use 8 in the script. Whenever you make a new type of monster, it starts with 8 in the Inspector. Suppose you want a slower monster -- you can easily see the 8 it starts with, and know that 4 is good for a "slow" monster.

If there is no normal value, like for monster hit points, can use something stupid in the script like -999, 1 or 99999. That way, when you make a new monster and test it, you'll see right away that you forgot to enter the hitpoints.

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 maninduw · Jan 13, 2014 at 01:46 AM 0
Share

Thank you for the explanation.

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

22 People are following this question.

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

Related Questions

How to expose member variables to the inspector in C#? 1 Answer

View script variables within an array of scripts in Inspector 1 Answer

Inspector Drop Down for Variables 0 Answers

Is there a way to extend the amount of values for inspector? 0 Answers

Show multiple attached scripts variables in one script in the 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