• 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 /
This question was closed Apr 12, 2015 at 01:11 PM by meat5000 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Notter · Apr 12, 2015 at 12:24 PM · inspectorpublic variable

is there a way to minimize amount of public items in inspector?

I've ran into a situation in my UI that the inspector is holding way too many public variables. And since i'm new to unity, i'm not sure if this is common practice, or should i use alternative ways, like "GetComponents" or "Resource.Load"

here are some examples of my situation:

alt text

alt text

as you can see, my main issue is with the sprites. since i hide/show/switch them from code, i need a reference for them.

so all i'm asking, is if this is a common practice, or is there a better way?

1.jpg (46.8 kB)
2.jpg (36.9 kB)
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

  • Sort: 
avatar image
2
Best Answer

Answer by saud_ahmed020 · Apr 12, 2015 at 12:28 PM

http://answers.unity3d.com/questions/907918/is-there-any-way-to-write-one-hideininspector-for.html

use it for hiding public gameobjects in inspector

 [HideInInspector]
Comment
Add comment · Show 5 · 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 Cherno · Apr 12, 2015 at 12:39 PM 0
Share

Î converted the post to an answer since it accurately answers the question :)

avatar image Notter · Apr 12, 2015 at 12:42 PM 0
Share

Okay, this helps with public variables that i don't want to change from inspector, so thanks :)

what about the sprites that needs reference, should i leave it the way it is?

avatar image TheRobWatling · Apr 12, 2015 at 12:51 PM 0
Share

You can use Unitys resource.load for loading sprites ins$$anonymous$$d of using inspector fields.

You can also do GameObject.Find on start to find objects but it's advised to never use GameObject.Find outside of start as its expensive.

avatar image Notter · Apr 12, 2015 at 01:09 PM 0
Share

Do i have to put my sprites in folder named Resources in order for this to work?

avatar image saud_ahmed020 · Apr 12, 2015 at 03:16 PM 2
Share

@Notter You can use following code to load from resources.

 Sprite sprite = Resources.Load<Sprite>("spriteName") as Sprite;
 spriteRenderer.sprite = sprite;

  

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

20 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

Related Questions

Cannot assign Public GameObject variable in Inspector... 2 Answers

Some Public Variables doesn't display in Inspector 2 Answers

GUIText new line through inspector 1 Answer

C# | public variables in parent class should not show up in child class 1 Answer

Can you make changes to exposed public variables persist in 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