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 crypticmind · May 03, 2013 at 12:00 AM · componentpropertiescustom-editorglobal variable

How to define component properties globally

Hi,

Let's say I have a component that has some properties, like some mouse cursor icon and some icons, and I plan to create several scenes with the same component with the same property values attached to each main camera.

How could I define these values just once globally and reuse (share) that configuration across all instances of the component in all scenes?

I envision I will have to create some custom Editor window to allow the designer to define these values. But I need to know if it possible to store the resource references somewhere and link all component instances to this.

Thanks in advance for any help.

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

1 Reply

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

Answer by proandrius · May 03, 2013 at 12:23 AM

MyGlobalVariables.cs

 public static int myVar = 0;
 
 public static void UpdateVar(int newVar)
 {
     myVar = newVar;
 }

And you don't need to assign this script anywhere and you can access it from anywhere by writing MyGlobalVariables.UpdateVar(5);

Comment
Add comment · Show 4 · 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 crypticmind · May 03, 2013 at 12:50 AM 0
Share

As far as I can tell, static properties can only be set programmatically. I'm still missing here how can I let the designer specify these in a custom editor window and make these available at run time.

avatar image proandrius · May 03, 2013 at 12:54 AM 0
Share

$$anonymous$$ake Editor script which changes these values. Or assign it to the GameObject and add make script to that object:

  function Awake () {
         DontDestroyOnLoad (this.gameObject);
     }
avatar image crypticmind · May 03, 2013 at 01:32 AM 0
Share

Your answer led me to this other answer: http://answers.unity3d.com/questions/39717/static-variables-assigned-in-the-inspector.html

I ended up putting all the properties in a prefab with a script, and an accessor property to statically reach out to those properties from any other classes.

Thanks for the help.

BTW, I just read your blog http://www.canonepersonmakerpg.com and I found out that we're both undertaking the same type of project, except that $$anonymous$$e is an adventure game ins$$anonymous$$d of an RPG. Best of luck with your entreprise! If you wish to take a look, I'm blogging my progress here: http://anadventuregame.blogspot.com

Cheers

avatar image proandrius · May 03, 2013 at 12:31 PM 0
Share

Cool, take care!

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

13 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

Related Questions

How to change Component's (MonoBehaviour Script) header (name) shown in Inspector from Custom Editor? 0 Answers

Custom Editor Properties Revert to Defaults on Play 4 Answers

2D Animation does not start 1 Answer

How do I modify an existing default component? 0 Answers

Changing properties of component without Inspector using C Sharp 3 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