Basics ​
Core Concepts: GameObjects, Components & Prefabs ​
GameObject vs. Component: A GameObject is the fundamental object in a Unity scene. Think of it as an empty container. A Component is a piece of functionality that you attach to a GameObject. For example, to make a cube in a scene, you create a GameObject, and Unity automatically attaches a Transform component to it (which controls its position, rotation, and scale). You would then add other components like a
Mesh Filterto define its shape and aMesh Rendererto make it visible.Prefab Scalability: A Prefab is a pre-configured GameObject stored as an asset. It acts like a template. When you create an instance of a Prefab in your scene, any changes you make to the original Prefab asset will automatically apply to all instances. This is a massive help for scalability because you can easily make a change to a single Prefab (e.g., changing an enemy's health or a door's material), and that change will propagate across every instance of that Prefab in your entire game, saving a huge amount of time. You can also override properties for individual instances while still inheriting other changes from the Prefab.
Update Loops & Physics ​
Awake(): Called once when the script instance is being loaded. Use this for initialization tasks like setting up references to other objects. It runs even if the script is not enabled.Start(): Called once just before the first frame update, but only if the script is enabled. Use this for initialization that depends on other objects already being initialized withAwake().Update(): Called once per frame. Use this for general game logic like handling input, non-physics movement, and timers. Its frequency varies with the frame rate.FixedUpdate(): Called at a fixed time interval, independent of the frame rate. Use this for physics calculations, like applying forces to aRigidbody, to ensure consistent and predictable physics behavior regardless of the player's computer performance.LateUpdate(): Called once per frame, after allUpdate()functions have finished. Use this for things that need to happen after all other objects have moved, like a camera that follows a player.
Collision Detection: ​
The Collision Detection mode on a Rigidbody component determines how it interacts with other objects.
Discrete: This is the default and most performant option. It checks for collisions at the end of each
FixedUpdate. However, fast-moving objects might pass right through a collider without a collision being registered (known as "tunneling").Continuous: This mode is more CPU-intensive and is designed to prevent tunneling for fast-moving objects. It uses a sweep test to find the first point of contact, ensuring collisions with static colliders are not missed.
Continuous Dynamic: This is the most computationally expensive mode. It's similar to
Continuousbut also checks for collisions against other dynamic rigidbodies.