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
0
Question by Dichotomia · Sep 30, 2014 at 05:56 AM · c#inspectorpublic variabledecimal

C# public decimal variable not showing up in inspector

Item Class:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 [System.Serializable]
 
 public class Items
 {
     public string strName;
     public float fPrice;
     public decimal dPrice;
     public GameObject goItem;
 
     public string getName
     {
         get { return strName; }
         set { strName = value; }
     }
 }

When a list is created from this class, fPrice shows up in the inspector but dPrice doesn't. Any ideas why?

Comment
Add comment · Show 2
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 Addyarb · Sep 30, 2014 at 06:49 AM 0
Share

Do you really need a decimal for dPrice? That's the only reason I can guess it would not show up.

avatar image Dichotomia · Sep 30, 2014 at 08:07 AM 0
Share

It's not necessary, but I am trying it out because my game itself deals with money rather heavily (including cents, not just dollars), that's why I thought perhaps using decimal might be better since I need to show the 0s at the back without concatenating them at the back of the string.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Ashkan_gc · Sep 30, 2014 at 07:11 AM

Only limited few types are serialized by unity and copied in Instantiate and shown in inspector. int and float are the only number types if I remember correctly. So short, uint, long and many others are not shown. First of all these types are not usually used in games, secondly they wanted a simple and fast serializer with the things required and thirdly because they realized the need to change this in some situations, they added support for custom serialization code using an interface in 4.3.

In this way only those who use the feature will pay for it and their serialization code will not become hard to maintain as well.

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 mattyman174 · Sep 30, 2014 at 07:03 AM

I would imagine its because Decimal is used for very high precision and an accidental change to a Decimal number especially in a public variable exposed in the inspector could have unforeseen consequences.

Take these 2 numbers for example.

1.100000

1.1

On the surface you could say they are identical, simply enough if you store either one as a Float it will be 1.1. However stored as a Decimal the 2 numbers are very different. Decimal is for high precision and will store the trailing 0's and i would imagine to avoid confusion they do not make Decimals visible in the inspector.

I'm curious as to why your using a Decimal in the first place. System.Decimal is stored as 128bits and unless you intend to use the precision i would recommend you stick with Float.

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 Dichotomia · Sep 30, 2014 at 08:09 AM 0
Share

$$anonymous$$y only reason for wanting to use that is because of the monetary system in my game, since I have cents in them and need to display 0s at the back; I have not changed my codes, though, they are still functioning from my float variables until I find a better alternative.

avatar image steakpinball · Oct 01, 2014 at 06:02 PM 1
Share

You should look into string formatters to show trailing zeros http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.90).aspx

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make public variable read-only during run-time? 3 Answers

Inspector vs Script: Component best practice? 1 Answer

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

Multiple Cars not working 1 Answer

A node in a childnode? 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