Unity has a class in the UnityEngine namespace called Object, which acts as a base class for all objects that Unity can reference in the editor. Classes which inherit from UnityEngine.Object have special functionality which means they can be dragged and dropped into fields in the InspectorA Unity window that displays information about the currently selected GameObject, asset or project settings, allowing you to inspect and edit the values. More info
See in Glossary, or picked using the Object Picker next to an Object field.
This page provides an overview of the Object class and its common uses when scripting with it. For an exhaustive reference of every member of the Object class, see the Object script reference.
When creating your own objects via scripting, you typically do not want to inherit directly from Object. Instead, you should inherit from a class designed to be more specific to your goal.
For example, you should inherit from MonoBehaviour if you want to write a custom component which you can add to a GameObjectThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary, to control what the GameObject does or provide some functionality relating to it.
Or, you should inherit from ScriptableObject if you want to create custom assets which can store serialized data. Both of these inherit from Unity’s Object class, but provide extra functionality to suit those purposes.
Note: Unity’s Object class is in the UnityEngine namespace. This is different from .NET’s base Object class, which has the same name, but is the System namespace, and is not included in the default script template, so that the names do not clash. You can still inherit your classes from .NET’s System.Object if you want to create classes in your script which do not need to be assigned in the inspector.
Unity’s Object class acts as the base class for most of Unity’s built-in classes such as GameObject, Component, Material, Texture, MeshThe main graphics primitive of Unity. Meshes make up a large part of your 3D worlds. Unity supports triangulated or Quadrangulated polygon meshes. Nurbs, Nurms, Subdiv surfaces must be converted to polygons. More info
See in Glossary, SpriteA 2D graphic objects. If you are used to working in 3D, Sprites are essentially just standard textures but there are special techniques for combining and managing sprite textures for efficiency and convenience during development. More info
See in Glossary, and many more, which means all of these types can be dragged and dropped into these reference fields in the inspector.
If a field in the inspector specifies a specific type of class (such as Texture), then Unity restricts you from dropping any other type of object into that field, and the object picker will only show objects of the correct type.
The above image shows three types of object field in the inspector.
The first is of type Object, meaning any Unity Object can be assigned to this field. You could drop any type of object into this field, whether it was a GameObject, a Texture, an Audio ClipA container for audio data in Unity. Unity supports mono, stereo and multichannel audio assets (up to eight channels). Unity can import .aif, .wav, .mp3, and .ogg audio file format, and .xm, .mod, .it, and .s3m tracker module formats. More info
See in Glossary, or anything else. This is not usually very useful, and it’s better to make your fields be more specific about what they should accept.
The second shows that its type is “Texture”, as shown in the parentheses. Texture is a built-in Unity class, and this means you can drop any Texture Asset into this field. Unity has two classes which inherit from this, Texture2D and RenderTexture, which means you can drop either of these types into this field.
The third shows that its type is “Food”. There’s no built-in Unity class with this name, so this example is showing a custom user-made class which inherits from Object. If you were to subsequently create classes which inherit from “Food”, such as “Apple” and “Banana”, you would be able to assign references to instances of these classes into the Food field, because they inherit from that type.
The Object class provides a few methods which allow you to Instantiate and Destroy them properly, as well as finding references to Objects of a specific type.
For more information on the API for the Object class, see the script reference page for Object.
Object
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.