Theory Flashcards
(117 cards)
What are the basic principles of Unity architecture and how do they affect game development?
The basic principles of Unity architecture revolve around GameObjects, Components, Scenes, and Scripts:
GameObjects: These are the fundamental entities in Unity, representing characters, props, cameras, lights, etc.
Components: Components are attached to GameObjects to add functionality or behavior. Examples include Rigidbody for physics, Renderer for visuals, and Scripts for custom logic.
Scenes: Scenes are collections of GameObjects that make up a level or a portion of a game world. They help organize the game’s structure and content.
Scripts: Scripts are written in languages like C# and are attached to GameObjects as Components. They define the behavior and interactions of GameObjects in the game.
What Phyics mechanics have you used to create realistic object movement?
I’ve utilized rigid body dynamics, which simulate the motion and interactions of objects based on their mass, forces, and collisions. Additionally, I’ve employed techniques like raycasting for precise object detection and physics-based animation blending for smoother movement transitions.
What is the Rigidbody component?
The Rigidbody component in Unity is essential for simulating realistic physics in games. It’s attached to GameObjects to give them physical properties like mass, gravity, and forces. This allows objects to respond naturally to collisions, forces, and movement commands within the game world. Rigidbody is crucial for creating realistic interactions between game elements, enhancing gameplay dynamics, and ensuring objects behave according to the laws of physics, making games more immersive and engaging for players.
What is the Collider component, what colliders exist? what is the difference between in isTriggered mode and normal?
The Collider component in Unity defines the shape of objects for collision detection and physics. There are types like Box, Sphere, Capsule, and Mesh Colliders.
In normal mode, colliders physically interact with other objects, affecting their movement. In isTrigger mode, colliders don’t cause physical reactions but trigger events when other objects enter their area, useful for creating game mechanics like checkpoints or collectibles.
What is Sprite Renderer component, What is the difference between order in layer and sorting layer?
The Sprite Renderer component in Unity displays 2D graphics or sprites on GameObjects in the game world. It allows developers to easily add visual elements like characters, backgrounds, or objects to their games.
Order in Layer: Determines the rendering order of sprites on the same sorting layer. Higher values appear in front of lower values.
Sorting Layer: Defines groups of sprites that can be controlled independently for rendering order. Each layer can have its own order of rendering relative to other layers.
Name the main life cycle of monobehaviour
The main lifecycle of MonoBehaviour in Unity consists of several key methods:
Awake(): Called when the script instance is being loaded. This is used for initializing variables or setting up references.
Start(): Called before the first frame update, after Awake(). This is often used for initialization that requires all GameObjects to be initialized.
Update(): Called once per frame. This is where most of the game’s code and logic for updating GameObjects typically goes.
FixedUpdate(): Called at fixed intervals, typically used for physics-related calculations. This ensures that physics calculations are consistent across different devices.
LateUpdate(): Called after all Update() functions have been called. Useful for actions that need to be performed after all Update() calls are completed.
OnEnable(): Called when the object becomes enabled and active. This is often used for re-initialization or setting up event listeners.
OnDisable(): Called when the object becomes disabled or inactive. This is used for cleaning up resources or removing event listeners.
OnDestroy(): Called when the GameObject is being destroyed. This is where you release any resources or perform any final cleanup.
Understanding and utilizing these methods correctly is crucial for managing the behavior and lifecycle of GameObjects in Unity.
How do the the methods of Awake, Start, Update, Fixed Update Works?
Awake(): This method is called when the script instance is being loaded. It’s typically used for initialization tasks that need to be performed before the game starts. Awake() is called even if the GameObject is not active in the scene hierarchy.
Start(): Start() is called before the first frame update, after Awake(). It’s often used for initialization that requires all GameObjects to be initialized. Start() is not called if the GameObject is inactive.
Update(): Update() is called once per frame and is where most of the game’s code and logic for updating GameObjects typically goes. It’s used for tasks that need to be performed continuously, such as player input processing, animation updates, or AI behavior.
FixedUpdate(): FixedUpdate() is called at fixed intervals, typically used for physics-related calculations. This ensures that physics calculations are consistent across different devices, regardless of the frame rate. FixedUpdate() is commonly used for rigidbody physics interactions, such as applying forces or performing movement calculations.
Why is it better to use Update, Fixed Update, Late Update?
The choice between Update, FixedUpdate, and LateUpdate depends on the specific needs of your game and the behavior you’re implementing:
Update(): This method is called once per frame and is suitable for general-purpose code that doesn’t require strict timing, such as player input processing, animation updates, or non-physics related movement. However, Update() is not frame-rate independent, so if the frame rate drops, the game might appear less smooth.
FixedUpdate(): FixedUpdate() is called at fixed intervals, typically synchronized with the physics engine’s fixed time step. It’s ideal for physics-related calculations, such as applying forces, performing movement calculations for Rigidbody objects, or handling physics-based interactions. FixedUpdate() ensures consistent physics behavior across different devices, regardless of the frame rate.
LateUpdate(): LateUpdate() is called after all Update() functions have been called. It’s useful for actions that need to be performed after other updates have occurred, such as camera follow behavior, where you want the camera to update after the player has moved. LateUpdate() can also be used for procedural animation updates or other actions that depend on the state of GameObjects after all other updates have been processed.
Choosing the appropriate update method ensures that your game behaves correctly and efficiently. By using FixedUpdate() for physics-related calculations, you ensure consistent physics behavior. Update() is suitable for general-purpose code, while LateUpdate() is useful for actions that need to be synchronized with the state of GameObjects after other updates have occurred.
Is it possible to change the frequency of Fixed update, why do it?
Yes, you can change the frequency of FixedUpdate by adjusting the Fixed Timestep in the Time settings. This is done to balance performance and accuracy:
Lower Frequency (increase timestep): Improves performance but reduces physics accuracy.
Higher Frequency (decrease timestep): Enhances physics accuracy but can impact performance.
Difference between Awake and Start method, what are they used for ?
Awake() is called when the script instance is being loaded, used for initialization tasks like setting up references.
Start() is called before the first frame update, often used for initialization requiring all GameObjects to be initialized.
What is scriptable object, what pattern programming does it implement?
A ScriptableObject is a data container in Unity used to store data independently from scene instances. It implements the Singleton pattern, allowing shared data to be accessed by multiple objects without duplicating the data.
What is PlayerPrefs, What types of data can be stored there? What storage ways do you use at unity?
PlayerPrefs is a class in Unity used to store and retrieve player preferences between game sessions. It can store integers, floats, and strings. In Unity, other storage methods include serialization, databases, and cloud services for more complex data management.
What animation did you work with?
I’ve primarily worked with built-in Unity animations, utilizing features like Animator and Animation components to create movement and interactions within the game world.
What is DrawCalls, and how do you reduce their numbers? How does butching work?
Draw Calls are requests made by the CPU to the GPU to render objects. Reducing their numbers improves performance. This can be done by optimizing materials, using texture atlases, and combining meshes. Batching combines multiple objects into a single draw call, reducing CPU-GPU communication overhead.
What is Sprite Atlas, When Should you ask an artist to pack sprites in a sprite atlas when it’s easier to do in editor?
A Sprite Atlas is a collection of multiple sprites packed into a single texture. You should ask an artist to pack sprites in a sprite atlas when:
There are many sprites in the scene.
Sprites share similar textures or materials.
You need to reduce draw calls and improve performance.
It’s beneficial even when it’s easier to do in the editor because it optimizes rendering performance and memory usage.
How can I optimize the size of an application?
You can optimize the size of an application in Unity by:
Texture Compression: Use appropriate texture compression settings to reduce the size of textures.
Asset Bundles: Load assets dynamically through asset bundles to reduce initial build size.
Code Stripping: Use code stripping options to remove unused code and reduce build size.
Audio Compression: Compress audio files to reduce their size without significant loss in quality.
Asset Optimization: Remove unnecessary assets, scripts, and components to reduce build size.
Platform-specific Optimization: Optimize assets and settings for specific target platforms to reduce build size.
Build Settings: Adjust build settings to exclude unnecessary files and reduce build size.
What ways do you know to optimize the use of RAM?
To optimize the use of RAM in Unity:
Asset Compression: Compress textures, audio, and other assets to reduce memory usage.
Asset Streaming: Load assets dynamically as needed instead of loading everything upfront.
Texture Size Reduction: Use smaller texture sizes and mipmaps to reduce memory consumption.
Object Pooling: Reuse GameObjects instead of instantiating and destroying them to minimize memory allocations.
Memory Profiling: Use Unity’s profiler to identify memory-intensive areas and optimize accordingly.
Texture Atlases: Combine multiple textures into a single atlas to reduce memory overhead.
Script Optimization: Optimize scripts to minimize memory allocations and deallocations.
Platform-specific Optimization: Optimize settings and assets for target platforms to reduce memory usage.
What is Unity Events?
Unity Events are a messaging system used to trigger functions or methods in response to specific actions or conditions in Unity. They allow for decoupling of code and can be used to create modular and flexible systems.
What is Raycast?
A Raycast is a physics-based method in Unity used to detect objects along a line or ray in a scene. It’s commonly used for collision detection, object interaction, and determining line of sight.
Did you work with ParticleSystem? what problems can be solved by using Particle System?
Yes, I’ve worked with Particle Systems in Unity. They’re used to create various visual effects like fire, smoke, explosions, and magical spells. Particle Systems can solve problems such as creating realistic environmental effects, enhancing gameplay feedback, and adding visual polish to games.
What particle systems do you use to create the effects of fire, smoke, or explosion in games?
To create effects like fire, smoke, or explosions in Unity games, I utilize the Particle System component. This component allows me to generate and control thousands of particles, defining their behavior, appearance, and interaction with the environment.
What is Canvas? How many canvas can exist on stage at the same time? When is there a need to make more than one canvas?
In Unity, “Canvas” is a UI (User Interface) component used to render UI elements like buttons, text, and images in a game. There is no limit to the number of canvases that can exist on the stage simultaneously. Multiple canvases are often used when different UI elements require separate rendering settings or when organizing UI elements into layers for better management and performance.
What Renderer modes in Canvases, Do you know what is each of them used for?
In Unity’s Canvas component, there are three Renderer modes:
Overlay: Renders UI elements on top of the scene, ignoring depth and perspective. It’s commonly used for HUDs, menus, and other elements that should always be visible.
Camera: Renders UI elements within a specified camera’s view, allowing for depth and perspective effects. It’s useful for creating UI that interacts with the 3D environment or for creating in-world UI elements.
World Space: Renders UI elements as 3D objects within the scene, allowing for interaction with other GameObjects. It’s used for complex UI elements that need to move, rotate, or scale in 3D space.
How will the procedure for drawing UI Elements be determined? What can you control?
The procedure for drawing UI elements in Unity is determined by the Canvas component’s properties and hierarchy. You can control:
Canvas Render Mode: Choose between Overlay, Camera, or World Space to define how the UI is rendered.
UI Element Hierarchy: The order of UI elements in the hierarchy determines their drawing order.
Sorting Layer and Order in Layer: Control the rendering order of canvases and UI elements within the same layer.
Anchors and Pivot: Define the position and scaling behavior of UI elements relative to their parent.
RectTransform: Adjust size, position, and rotation of UI elements.
These settings allow you to manage the layout, rendering, and interaction of UI elements effectively.