x


Primitive data types (for code, not modeling)

I'm trying to find a list of Unity's primitive data types. As I'm searching I'm running into a conceptual collision between modeling primitives and code primitives, two very different subjects.

Examples would be: int, float, double, boolean, void.

When coding I prefer to statically type numbers as int, float or double opposed to leaving it to a catch all Number class.

more ▼

asked Sep 29, 2010 at 02:05 PM

redlamp gravatar image

redlamp
39 1 2 7

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

There is no "catch all" number class in Unity.

Unity uses Mono for its scripting, so it has the same set of integral types as .Net

See these reference pages on MSDN for the full list:

.Net Integral Types Table

.Net Built-In Types Table

Both C# and Unity's Javascript (a.k.a. "UnityScript") share this set, although Unity's JS has a couple of slight differences:

  • bool in C# becomes boolean in Javascript
  • string in C# becomes String in Javascript (note, capital "S")
more ▼

answered Sep 29, 2010 at 02:31 PM

duck gravatar image

duck ♦♦
47.4k 129 188 457

Hey Pitt, but its behave warid. there is no difference between bit and byte type. even byte data type take only value true / false or 0 / 1.

it's really strange behavior of unity...

Aug 18, 2012 at 12:27 PM PAHeartBeat

@RAJPatel:
No, that's just the inspector of Unity which interprets a byte as boolean. It still is a byte and you can assign values between 0 and 255.

Again, it's just the default inspector that shows actually the wrong gui control for this type. You can create a custom inspector for your class and use another GUI control if you need to edit it in the inspector.

The best way however is to use an int instead. Memory management has usually a 4 byte alignement, so you don't really have any benefits of using byte except that it wraps at 256 to 0

Aug 18, 2012 at 02:03 PM Bunny83
(comments are locked)
10|3000 characters needed characters left

You don't exactly specify how primitive you want to get.

It's not really "Unity's" primitive data types exactly. Unity uses a customized subset of mono. Most of the primitive types like int, float, enum, etc. are short names for classes in the System library. Duck's links cover the most primitive of these.There are also the classes that were added by Unity (run-time and editor).

Keep in mind the syntactic differences between Unity js and mono, including different short names like using boolean in stead of bool and String in stead of string.

more ▼

answered Sep 29, 2010 at 02:40 PM

skovacs1 gravatar image

skovacs1
11.1k 16 34 106

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x537
x336
x193
x44
x13

asked: Sep 29, 2010 at 02:05 PM

Seen: 8039 times

Last Updated: Aug 18, 2012 at 02:03 PM