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
25
Question by ilkejav · Oct 23, 2010 at 06:48 PM · variableinspectorpublic

Invisible Public Variable in Inspector

Is there any way of creating a public variable that doesn't show up in the inspector? We are currently working on a huuuge array (literally thousands of cells in it) and it works perfectly except from the fact that Unity's inspector tries to display it and crashed on a very regular basis.

The problem is that we need to make this variable public in order to have other scripts access it freely. But we cannot find a way to make the inspector ignore it.

We get the error message "too many heap sections" which means that somehow, somewhere Unity tries to sort the data and runs out of memory. We do not need to look at the data, so we'd like to NOT show it if possible.

BTW, when we close the inspector, Unity doesn't crash. That's how we know the source of the problem.

Any ideas?

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

5 Replies

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

Answer by boymeetsrobot · Oct 24, 2010 at 08:18 AM

Hi.

You would do something like this:-

public float notHidden; // Displayed
[HideInInspector] // Hides var below
public float hidden;
Comment
Add comment · Show 3 · 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 ilkejav · Oct 25, 2010 at 05:58 AM 0
Share

Very useful! Since this is very much specific to the Unity platform, we didn't know this feature existed. Thanks!

avatar image pctroll · Mar 31, 2014 at 08:21 AM 1
Share

Wow... this is just what I was looking for and it's a shame I cannot vote up.

avatar image cgeopapa · Jul 16, 2015 at 07:53 AM 1
Share

For Javascript it is like that:

     var notHidden: float; //Displayed
     @HideInInspector // Hides var below
     var hidden: float;
 
avatar image
23
Best Answer

Answer by Jesse Anders · Oct 23, 2010 at 11:36 PM

The attribute HideInInspector might be of use, as well as NonSerialized if you don't want the values of the variables to be saved with the scene.

Note also that in general at least, it's not necessary for a variable to be public in order for it to be accessible from outside a class/struct. (In C#, for example, it's common to use properties to facilitate controlled access to protected or private data.)

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 ilkejav · Oct 25, 2010 at 05:57 AM 0
Share

wow, super! I think this may be what we're looking for. Really appreciated!

avatar image Bengooch7 · Jul 24, 2015 at 01:03 PM 0
Share

Is there a way to have a number be NonSerialized and still be visible in the editor?

I'm working on a script that I need to monitor how a variable changes, but I need for it to clear and be assigned a new value when the scene starts. It's based on the time of day, down to the second. Currently, when I first attach the script and launch the scene I assume it serializes the number because it never changes after that.

avatar image
0
Wiki

Answer by fingerbib · Feb 28, 2015 at 02:42 AM

FYI, You could also use the Internal scope for your variable if you plan to only use it in the same assembly.

Comment
Add comment · 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
0

Answer by Er_ellison · Feb 05, 2018 at 03:59 PM

guys can we write this like here in my code ???

 [HideInInspector] public string myVar;

it doe not makes a serious problem in future ????

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 TheFishyDishy · Jul 30, 2021 at 02:12 PM 0
Share

This comment is four years late, but yes. You can indeed write the code like that.

It will not cause any serious problems. Its the same code but behind instead of before.

avatar image
0

Answer by the_real_ijed · Feb 07, 2018 at 07:12 PM

I think this is a better solution for when you set the value from another script:

 [System.NonSerialized] public int valueOfSomeThing;

Since it avoids bad data being stored in the scene.

[HideInInspector] still works but the above should solve the more recent complaints of the original script not working eight years after the original answers were given :)

Comment
Add comment · 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

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Public "char" parameter not showing on inspector? 2 Answers

How to set a public variable to a gameObject in the inspector through coding 1 Answer

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

Public variable not showing in Inspector(Solved) 1 Answer

Avoid public variable to get overwritten by the 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