Sample questions
Un Gameobject Component TransformDifficulty 1
In Unity, what determines the behavior and capabilities of a GameObject?
- aThe GameObject's name in the Hierarchy window
- bThe components attached to the GameObject✓
- cThe GameObject's position in world space
- dThe scene file the GameObject is saved in
Explanation:A GameObject by itself is just a container; its behavior and capabilities come entirely from the components attached to it, such as Transform, scripts, colliders, or renderers.
Un Gameobject Component TransformDifficulty 1
Which component can never be removed from a GameObject in Unity?
- aTransform✓
- bRigidbody
- cCollider
- dAudioSource
Explanation:Every GameObject has a Transform by default, and Unity does not allow removing it because every object needs a position, rotation, and scale in the scene.
Un Gameobject Component TransformDifficulty 2
A script has [RequireComponent(typeof(Rigidbody))] above its class declaration. What happens when this script is added to a GameObject that has no Rigidbody?
- aUnity refuses to add the script and shows a compile error
- bThe script is added, but it silently ignores any Rigidbody-dependent code
- cUnity automatically adds a Rigidbody component to the same GameObject✓
- dThe script is added and creates a warning at every frame in the Console
Explanation:RequireComponent makes Unity automatically add the missing dependency when the script is attached via AddComponent, so a Rigidbody is added alongside the script.
Un Gameobject Component TransformDifficulty 2
Which of these component types can a single GameObject have more than one instance of at the same time?
- aTransform
- bRigidbody
- cMeshFilter
- dAudioSource✓
Explanation:Unity allows attaching multiple AudioSource components to the same GameObject, for example to play several sounds independently; Transform, Rigidbody, and MeshFilter are limited to a single instance per GameObject.
Un Gameobject Component TransformDifficulty 1
In C#, what does GetComponent<Rigidbody>() return when the GameObject has no Rigidbody attached?
- aIt throws a NullReferenceException immediately
- bIt returns null; no exception, no parent search✓
- cIt returns a default Rigidbody with zero mass
- dIt returns the Rigidbody of the parent GameObject
Explanation:GetComponent<T>() returns null when no matching component exists on the GameObject; it does not throw and does not search parents or create a default instance.
Un Gameobject Component TransformDifficulty 2
What is the correct way to use TryGetComponent to safely get a Rigidbody?
- a
if (TryGetComponent<Rigidbody>(out var rb)) { ... }✓ - b
Rigidbody rb = TryGetComponent<Rigidbody>(); - c
if (TryGetComponent(Rigidbody) == true) { ... } - d
var rb = TryGetComponent<Rigidbody>().Value;
Explanation:TryGetComponent returns a bool indicating success and outputs the component through an out parameter, so it is used inside an if with an out var argument.