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 /
  • Help Room /
avatar image
1
Question by ademar111190pqn · Sep 14, 2016 at 02:47 PM · inspector

Set a variable to null on inspector tab

I have a Behaviour with a public var to be set on inspector:

 public class TestBehaviour : MonoBehaviour
 {
 
     public string test = null;
 
     void Update ()
     {
         Debug.Log ("Variable: " + test + ", is null? " + (test == null));
     }
 
 }

I want to set it to null:

alt text

But I am getting this log:

 Variable: , is null? False

The variable is empty but I want it to be null How set it as null with inspector?

screen-shot-2016-09-14-at-113259.png (10.1 kB)
screen-shot-2016-09-14-at-113259.png (10.1 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

2 Replies

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

Answer by lloladin · Sep 14, 2016 at 03:18 PM

you can't set a string to null you need to set it to an empty string like this

 Public string test = "";

i would recommend that you look up some basic C# syntax if you don't know this :)

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 ademar111190pqn · Sep 14, 2016 at 06:29 PM 0
Share

Yes, I can set it to empty and check with an test.Length == 0 but if I really need to set as null? I can't do it via inspector? Or if I can, how to do?

avatar image ademar111190pqn · Sep 14, 2016 at 06:41 PM 0
Share

I understood now, in c# I should use test = string.Empty and check with string.IsNullOrEmpty(test). Thank you

avatar image clarHandsome · Feb 22, 2019 at 03:53 PM 0
Share

@lloladin You are not answering the author's question.

Unfortunately, you can't set a string as null in the inspector. If you leave it blank, the string is empty. [Here][1].

[1]: https://feedback.unity3d.com/suggestions/inspector-add-option-for-null-strings

avatar image
0

Answer by clarHandsome · Feb 22, 2019 at 03:55 PM

@lloladin You're not answering the author's question.

Unfortunately, you can't initialize a string as null in the inspector. If left blank, it's initialized as string.empty ("").

Reference.

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

71 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Preprocessor conditional code for cleaner inspector options 1 Answer

Creating game objects from inspector 0 Answers

How do I bind the value of a public variable from the inspector to some other variable/constant? 0 Answers

public bool not showing in inspector 1 Answer

I have assigned it, but I get an error of Unassigned Reference Exception! 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