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 The-Oddler · Sep 04, 2011 at 10:50 AM · inspectorsingleton

Singleton & Inspector

Hi,

I have a popup-manager singleton, which creates itself first time you want to show a popup. It has some settings, which I would like to set in the inspector, but they don't show up (except for one, but that one is reset to it's default when the singleton object is created).

I have to following code:

 static UnityGrowl m_Instance;
 static readonly object padlock = new object(); //For thread safety
 //Creates the Popup Object only once, the first time it is needed
 public static UnityGrowl Instance
 {
     get
     {
         lock (padlock)
     {
             if(!m_Instance)
                 m_Instance = (new GameObject("Unity Growl")).AddComponent<UnityGrowl>();
             return m_Instance;
         }
     }
 }

 //GUISkin shows up in the inspector, but is Null in the object in the scene
 //The other stuff doesn't even show up in the inspector
 public GUISkin m_GUISkin;
 GUIStyle m_Style;
 public int m_Width = 240;
 public int m_XOffset = 5;
 public int m_YOffset = 5;
 public enum position{TopLeft, TopRight, BottomLeft, BottomRight}
 public position m_Position = position.TopRight;

When I say "doesn't show up in the inspector" I mean it doesn't for the script (when not attached to an object), when I make my first popup and look at the 'Unity Growl' object it does show the settings.

Is it possible to make it so that the settings do show up for the script itself, and they don't get reset ?

Thanks !

-P

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
1
Best Answer

Answer by aldonaletto · Sep 04, 2011 at 11:49 AM

The Inspector only shows and allows modification of variables for scripts assigned to objects - they are independent instances of the original script. If not attached to any object, the only way to modify the variables is editing the script, what isn't so bad at all (values modified in the Inspector survive even when you make extensive modifications in your script, and continue plaguing your life until you reset them with the Inspector "gear" button!).

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 The-Oddler · Sep 04, 2011 at 11:53 AM 0
Share

Ok thanks :P Didn't think it was possible but was worth the effort to ask :D

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Singleton class variables and inspector 0 Answers

Setting singleton assets through inspector 1 Answer

Script to create instance from in inspector 2 Answers

Unity3D 3.2, MonoDevelop debugger "inspector" problems 3 Answers

How to serialize an array of classes 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