• 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
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
avatar image maninduw · Jan 12, 2014 at 01:54 PM 0
Share
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 $$anonymous$$t points, can use somet$$anonymous$$ng 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 $$anonymous$$tpoints.

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

The box for entering a variable's value in the inspector is not where it should be. 0 Answers

Gameobject is set but doesn't show in the inspector 0 Answers

Change Inspector Variables Depending On Enum 2 Answers

Inspector Assigned Variables Not In Both Scenes 1 Answer

Problem with variables and inspector 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