Unity Basics 3. Assets & Prefabs
3. Assets & Prefabs
Asset workflow
Materials, Shaders and Textures
- Materials define how a surface should be rendered: textures, color, lighting…
- Shaders are scripts that calculate how color of a pixel should be rendered
- Textures are bitmap images that can be used to draw shapes to materials, but also manipulate material’s surface
Using materials
- Old Manual: Creating and Using Materials
- Materials are by default applied to the whole GameObject
- With ProBuilder, you can apply a material into individual parts of an object
- There are two ways to apply a Texture to a property.
- Drag it from the Project View on top of the Texture square
- Click the Select button, and choose the texture from the drop-down list that appears
Prefabs
- Manual: Prefabs
- Prefab is short for prefabricated object
- use cases…
- GameObjects you want to instantiate, i.e., create, during runtime
- “Same thing, but what if many?”
- not necessary completely identical, however!
- share common traits but have different details
Creating prefabs
- Manual: Creating Prefabs
- How to turn a GameObject into a Prefab:
1) Drag a GameObject from Hierarchy to Project view 2) It turns blue - It’s now an instance of a Prefab 3) You can now create multiple other instances of it
Open & select
- Manual: Editing a Prefab via its instances
- Open
- opens the Prefab in Prefab mode, a scene where only the Prefab exists
- Manual: Editing a Prefab in Prefab mode
- Select
- selects the Prefab asset in the Project window
Overrides
- Manual: Instance overrides
- Overrides dropdown menu
- lists all the overridden values (“overrides”) on this Prefab instance
- overrides can be applied to set them to be the new default in the Prefab asset
- …or reverted to discard your changes and go back to asset defaults
- overridden values in Inspector are indicated in bold
Extra: Nested prefabs
- Prefab inside Prefab
- Manual: Nested Prefabs
Extra: Instantiating Prefabs
- You can use code to create instances of prefabs when the game is running
- Manual: Instantiating Prefabs at run time