Version: Unity 6 Preview (6000.0)
Language : English
Garbage collection
Fundamental Unity types

Object-oriented development

Traditional Unity projects are object-oriented in two related ways:

  • They embrace the object-oriented programming philosophy, which is grounded in the concept of objects, their properties and functions, and the relations between these objects.
  • The original architecture of Unity projects uses an object-based model with types derived from UnityEngine.Object. In this model, scenesA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
    See in Glossary
    are composed of GameObjects which in turn interact with and are controlled by objects of other types.

An alternative to object-oriented development is data-oriented development, which is both a programming philosophy and a set of technologies that help you implement those principles. The data-oriented approach offers strong performance advantages at scale but can be more challenging for inexperienced developers to learn.

Object-oriented and data-oriented development are not mutually exclusive and you can combine elements from both. For information on data-oriented development, refer to Unity’s Data-Oriented Technology Stack.

Topic Description
Fundamental Unity types Some of the fundamental C# class representations of Unity objects, which you’ll almost certainly use and derive from in your code.
Transforming objects Moving and transforming objects by changing their position, rotation, and scale.
Managing time and frame rate Understand how Unity measures time so you can manage the rate at which time passes in your application and ensure values update according to the appropriate time scale.
Instantiating prefabs at runtime Instantiate prefabsAn asset type that allows you to store a GameObject complete with components and properties. The prefab acts as a template from which you can create new object instances in the scene. More info
See in Glossary
programmatically to create structures and impressive effects in your game with relatively little code.
Handling events Make your application responsive to events such as user input, object collisionsA collision occurs when the physics engine detects that the colliders of two GameObjects make contact or overlap, when at least one has a Rigidbody component and is in motion. More info
See in Glossary
, and physics and rendering updates.
Splitting tasks across frames Split the execution of a task synchronously across multiple scenes with coroutines. This can be useful for tasks that should progress gradually over several frames, such as a fade out effect.
Interacting with web servers Use the UnityWebRequest system to allow your application to interact with a web server via HTTP.
Adding functionality to objects at runtime Use the Unity Properties API to implement a visitor design pattern and add new operations to .NET objects at runtime.
Using common math functions Use common math functions, including trigonometric, logarithmic, and other functions in your application.
Using randomness Generate commonly required types of random values.
Gizmos and Handles Draw lines and shapes in the Scene viewAn interactive view into the world you are creating. You use the Scene View to select and position scenery, characters, cameras, lights, and all other types of Game Object. More info
See in Glossary
and Game view, as well as interactive handles and controls.
Null references Understand and diagnose null reference exceptions in Unity projects.
Unity attributes Use Unity-specific C# attributes to define special behavior for your code.

Additional resources

Garbage collection
Fundamental Unity types