You are on page 1of 10

10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog

Saturday, October 15, 2022  

Gyanendu Shekhar's Blog


Let's learn something new today!

Microsoft
DOWNLOAD
Add the extension

 UNITY3D C# DESIGN PATTERNS ENTITY FRAMEWORK SQL SERVER ABOUT ME 


CONTACT ME

Unity

Using GameObjects and Prefabs–


Unity Tutorial
 July 31, 2017  Gyanendu Shekhar  0 Comments  GameObjects, Prefabs

In last tutorial, we discussed about unity interface. In this article, we will see
how to use GameObject and prefabs in a unity application.

GameObjects Happy and Healthy Diwa


Kaleesuwari
Every object that you see in the game is a GameObject. It is the fundamental
object in unity. You can find all the GameObject in the hierarchy window.
GameObjects can have parent child relationship as we saw in last article.

GameObject Components
Alone GameObjects are nothing but the empty container, but when you will
add components to the GameObjects, it will add functionalities to them. By
default, there may be some components attached to your GameObjects. You
can see all the components of a GameObject in the Inspector window.

When you will create a new project in unity then by default there will be two
GameObjects in the hierarchy window.

Main Camera: Controls view of Game Window. What the camera will
see, the end user will see the same.
Directional Light: Provides light in any particular direction

DOWNLOA
the extension
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 1/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog

Select any one of the GameObject in the hierarchy window then you can see
the attached components in the Inspector window. Select Main Camera and
check its components:

Disable Component

To disable any component, uncheck the checkbox located at top left of the
component, as shown in above image (1. Uncheck to disable component). If
any component is disabled, it will be attached to the GameObject but its
functionality will not render in the scene.

Remove Component

To remove any component, click on the icon located at top right of the
component, as shown in above image (2. Click to remove component). On Click,
following list will be displayed. Click on the Remove Component.

DOWNLOA
the extension
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 2/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog

Add Component

Click on the Add Component button to add more components. On click, a


component list will be displayed.

You can also drag and drop items from assets folder to inspector window to
add component for any GameObject.

Transform Component

Every GameObject will have Transform component. You cannot remove


transform component from a GameObject. Transform component is having
three rows:

Position: Change the position of the GameObject.


Rotation: Change the rotation of GameObject.
Scale: Change the size of the GameObject.

You can also transform the GameObject using transform tools with mouse
buttons.

Change GameObject
Properties using Inspector
Inspector window also allows you to disable and rename the GameObject
along with other features.

Rename GameObject

Rename the text box located at top of the Inspector and hit Enter to change the
name of the GameObject.

Disable GameObject from Hierarchy


DOWNLOA
the extension
Uncheck the top left checkbox in inspector window to disable GameObject
from hierarchy window.
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 3/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog

Static GameObject

Static GameObject will not move at play time. These are non-moving
GameObjects.

Change Tag of GameObject

A tag is simply a string that can be used to reference one or more GameObjects
in the scene. You can group a type of GameObject with one tag like all the
enemy GameObjects in your game can be tagged as ENEMY tag. Change the
tag of a GameObject using Tag dropdown in inspector window.

Change Layer of GameObject

Layer controls the rendering priority of GameObject in the scene. Change the
layer of a GameObject using Layer dropdown in inspector window. You can
refer my Layer Mask tutorial to know more about Layers.

Create a GameObject
Primitive GameObjects

Primitive GameObjects can be created directly in the unity. Cube, Capsule,


Sphere, Cylinder, Plane and quad are the example of primitive 3D
GameObjects. You can use these GameObjects for testing purpose or any
other requirement. You can check details about them over here.

Right click in hierarchy window to create primitive GameObjects.

DOWNLOA
the extension
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 4/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog

You can also click on “Create” button in hierarchy window.

Create Parent-Child Relationship

You can create parent child relationship using GameObjects. Drag and drop
one GameObject to another to make it as the child of the another GameObject.

Prefabs
The prefab allows you to store a GameObject with all its components and
properties. Once a prefab is created the GameObject can be reused multiple
times across the scene and the projects.

Create a Prefab

Create Prefab by selecting Assets -> Create -> Prefab or Right Click to Assets
folder in Project window -> Create -> Prefab. Drag and drop a GameObject
from hierarchy to this newly created prefab.

DOWNLOA
the extension
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 5/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog

You can also create prefab by directly by dragging and dropping GameObject
from hierarchy window to the project window.

All the child GameObjects will be automatically included in the prefab.

Add prefab to scene as GameObject

Drag and drop prefab from project window (Asset Folder) to hierarchy to
instantiate prefab as the GameObject in the scene. You can instantiate same
prefab multiple times in a scene.

Edit Prefab

Select the prefab and you will see all of its properties and components in the
Inspector. Modify them upon your requirement, but all the modification will
DOWNLOA
the extension
also reflect on already instantiated GameObjects.

gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 6/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog

Edit Prefab in the Scene

If you edit the GameObject (added by prefab) in the scene, it will not edit the
prefab by default. But, if we want to reflect the same change in the prefab then
click on apply button in the prefab section of inspector window after selecting
the GameObject.

Empty GameObject

You can also create empty GameObject in the hierarchy just like Cube and
other GameObjects. It will only have Transform component. It is mostly used to
create the parent of the multiple GameObjects.

Hope you get an idea about GameObjects and prefabs in unity application.
Post your comments for queries and feedback. Thanks for reading.

Bio Latest Posts

Gyanendu Shekhar
Gyanendu Shekhar is a technology enthusiast. He loves
to learn new technologies. His area of interest includes
Microsoft technologies, Augmented reality, Virtual reality,
unity3d and android development.

DOWNLOA
the extension
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 7/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog

← Learning Unity Interface

Getting started with Scripts – Unity Tutorial →

Gyanendu Shekhar
Gyanendu Shekhar is a technology enthusiast. He loves to learn
new technologies. His area of interest includes Microsoft
technologies, Augmented reality, Virtual reality, unity3d and
android development.

DOWNLOA
the extension
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 8/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog

Leave a Reply
Your email address will not be published. Required fields are marked *

Comment

Name *

Email *

Website

Save my name, email, and website in this browser for the next time I comment.

Post Comment

DOWNLOA
the extension
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 9/10
10/15/22, 7:42 PM Using GameObjects and Prefabs– Unity Tutorial - Gyanendu Shekhar's Blog

Copyright © 2022 Gyanendu Shekhar's Blog. All rights reserved.


Theme: ColorMag by ThemeGrill. Powered by WordPress.  

DOWNLOA
the extension
gyanendushekhar.com/2017/07/31/using-gameobjects-prefabs-unity-tutorial/ 10/10

You might also like