12 Weeks with Unity: Week 3 - Materials and Prefabs

Apr 01, 2018 at 09:30 pm by -gToon

This is the third of a series of articles that cover my journey learning and exploring one of the most powerful indie game creation tools available - Unity.

I’ll be sharing my knowledge and discoveries over a 12 week period. Each week I’ll post primarily on the process of learning Unity 3D along with other topics such as the history of the game engine, the community, and prominent artists/creators.

Last week I covered setting up a Unity project, learning the interface, understanding what a “game object” is and working with assets. I’ve been using the Lynda.com course, “Unity 3D Essential Training” by Craig Barr as a guide.

Check out current Autodesk Promotions Here!

RELATED: 12 Weeks with Unity

Unity Materials

Unity materials are definitions of how the surface should be rendered including references to textures, any tiling information, and how lighting is going to respond    to it as well. So materials, textures, shaders, these are all the things that we work with to get the overall look of an object in a scene. - Craig Barr

I’ve always been a bit confounded with the difference between materials, shaders, and textures. I’m glad I chose the Unity 3D Essential Training because I understand these concepts so much better now. Textures are images applied to an object whereas materials are a set of instructions to Unity (or any other 3D application) about what the object should look like. Shaders are small scripts that tell how the pixels of an object should be colored. Materials and Shaders are closely connected and often overlap.

This is a simplifaction of the texture/material/shader interaction, but at least I understand the differences and major functions now. Unity has excellent documentation and I was able to further my understanding by reading the section on these topics in the current manual.

Check out current Autodesk Promotions Here!

 

Applying Materials in Unity

As I’m beginning to understand, Unity is made for ease of use and working with materials is no exception. Unity has a large number of shaders built into the engine. Here is a list straight from the manual:

In addition to the Standard Shader, there are a number of other categories of built-in shaders for specialized purposes:

  • FX: Lighting and glass effects.
  • GUI and UI: For user interface graphics.
  • Mobile: Simplified high-performance shader for mobile devices.
  • Nature: For trees and terrain.
  • Particles: Particle system effects.
  • Skybox: For rendering background environments behind all geometry
  • Sprites: For use with the 2D sprite system
  • Toon: Cartoon-style rendering.
  • Unlit: For rendering that entirely bypasses all light & shadowing
  • Legacy: The large collection of older shaders which were superseded by the Standard Shader

It’s often easier to simply create your own material for a particular object. Again this process is very easy. Once you choose to create a material you simply use the inspector window (at the right) to build the elements you want (roughness, shininess, etc.). Another cool thing about materials in Unity is that they are always live meaning you can go back and change them at any time.

Note that if you create a material for a model in another program (Blender, for example) use the .fbx format to export and then import to Unity because it brings the materials over as well as the model itself. Unity reads them perfectly.

 

 

Prefabs in Unity

One of most impressive features of Unity is the ability to create prefabs. Prefabs are groups of things you have assembled (parts of a wall, model, anything…) so you can use “instances” of them anywhere in your scene. Since having a low poly count is essential to creating games that everyone can play, using prefabs will lower the poly count because the engine will only read your prefab once even if you have dozens of instances in your scene. Awesome, huh?

Prefabs are ridiculously easy to create and use in Unity. You simply create an empty game object and then drag and drop the components you want for the prefab. Organize them (elements of a wall, for example) and then right click in the assets window at the bottom of the Unity interface and choose “create prefab”. Oh, you have to make sure you are in your “prefab folder” to create a prefab as it’s just easier to have then all grouped together.

Once your prefab is created, name it then drop and drag the object you put together in the hierarchy right on top of the prefab. All of the components you put together will now be a prefab you can use anywhere in your scene!

Next Week: Level Building in Unity


Nvidia Store