Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Why isn't my public short showing in the inspector?

Discussion in 'Scripting' started by noatom, Apr 10, 2014.

  1. noatom

    noatom

    Joined:
    Apr 9, 2014
    Posts:
    21
    As I come from a c++ background, I might make some stupid mistakes. Anyway, I have a script that simply has:

    public short direction = 1;

    I added the script as a component, but the direction doesn't show in the inspector, why?
     
  2. bigmisterb

    bigmisterb

    Joined:
    Nov 6, 2010
    Posts:
    4,221
    post the rest of the code.
     
  3. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    I'm not fully sure, but I think Unity doesn't serialize properly short and double. (Someone can surely correct me, but those two types are not displayed by the Inspector, and usually that means a lack of serialization)

    You should try;

    Code (csharp):
    1.  
    2. public int direction = 1;
    3.  
    instead.
     
  4. Entwicklerpages

    Entwicklerpages

    Joined:
    Aug 31, 2013
    Posts:
    14
    Yeah! C++! Whoo! :D

    Ok, back to the question.

    The inspector cannot show you all datatypes. There are some restrictions.
    He can show you intengers but no shorts.

    If you want to use shorts in the inspector you must use a trick. You can create a custom inspector (look in the documentation or google after it). In this Inspektor you use an integer. Everytime you want to give your script this integer to its short member you just convert it.

    But it is easier if you simply use an integer at all.

    Edit: @bigmisterb LightStriker just a little bit faster than me :p
     
  5. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,716
    Sure... But I'm wondering if Unity is able to serialize those. If not, even displaying won't help much.
     
  6. noatom

    noatom

    Joined:
    Apr 9, 2014
    Posts:
    21
    Well, I know the issue now.
     
  7. Giometric

    Giometric

    Joined:
    Dec 20, 2011
    Posts:
    170
    I've run into this issue with the long and double types, so I'm assuming short is the same. Unity won't serialize them. Even with a custom inspector using int to show/edit the values, they don't get saved; they all just get reset to 0s. In your case it's not a big problem, as an int will serialize just fine and can store any value a short could store. If you need something bigger than what an int could store you could probably convert it to an array of bytes (which do serialize) and store it that way, saving and restoring as needed to show it nicely in the inspector.