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
0
Question by MvD · Dec 06, 2010 at 12:01 PM · editor-scriptingvalues

Per-application versus per-level editor values

Hi fellow Unity developers,

When I attach a script to a GameObject in the hierarchy, its public members become visible in the Unity editor. This is a great feature, because it means everyone can tune values when the game is actually running. And you can just drag assets to make them available in scripts.

My problem is that the hierarchy is part of a scene, i.e. the (tuned) values are specific to that level only. After finding the right value, you have to copy them to all the other levels. For some values, this is fine. You want to set them differently for each level. However, some values are essentially game-global.

So my question is: is there a simple way to get per-game (or per-application) parameters in the Unity editor? I can do it by creating an empty 'common' level with just a dummy cube with a script attached that has my game-global values in a class. When I start a normal level, I use Application.LoadLevelAdditive(), which gives me access to the values in the class (in the next frame). This works, but it seems a bit too complicated.

Thanks,

 Mattijs
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

2 Replies

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

Answer by Loius · Dec 06, 2010 at 04:23 PM

The solution is to make them prefabs and, when you need to change all instances, use the GameObject -> Apply Changes to Prefab menu option.

Alternately, use private vars in your scripts if they're not going to change, and / or give them a default value.

private var potatoes = 7;

This way they can't be accidentally changed in the editor. If you give a default value to a non-private var, keep in mind that any changes in the inspector will overwrite it, and if you change the default value later, it won't update the values on the existing objects.

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 MvD · Dec 06, 2010 at 05:59 PM 0
Share

Right, so I should split my tuning values into two scripts. The values that can be different per level go into script 1, and for the game-global values, I can create prefabs as you suggested. of course I can make stuff private, but being able to change values from the editor while the game is running is really useful...

avatar image MvD · Dec 06, 2010 at 09:45 PM 0
Share

Oh, and I forgot: thanks for answering my question:) Greatly appreciated!

avatar image
0

Answer by Anton Petrov · Dec 06, 2010 at 04:20 PM

Call DontDestroyOnLoad( this.gameObject ) method in your global script's Start() method. And it will stay forever.

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 MvD · Dec 06, 2010 at 06:02 PM 0
Share

Thanks for the reply. I don't think this helps, however. The problem is that multiple instances of the script are created, one per level. For some of the values in the script, this is fine (e.g. the amount of money when the level starts). For others (e.g. gravity in the game), it doesn't work. If I change the script value, I have to change it for each level where I have attached the script to a gameobject.

avatar image MvD · Dec 06, 2010 at 06:04 PM 0
Share

I should add that the problem is not that I need the same values in level 2 after playing level1. We directly start different levels from the editor at the moment.

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

Values set by [ExecuteInEditMode] script revert back in play mode. 2 Answers

Saving dictionary from editor mode in play mode 1 Answer

Editor Script - Multi-Editing Value Increase/Decrease Issue 1 Answer

Setting variables in public class to values from editor script 3 Answers

How can I edit model import settings from a script? 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