Featured_Image7

Tips for Creating Better Games and Working More Efficiently in Unity

‌‌
Unity is an extremely powerful game engine with the capabilities to tackle just about any game project you may have in mind, whether it's a 2D side-scroller for the desktop or a 3D mobile game. As you start to work more in Unity, you'll find ways to speed up your workflow and techniques to help you create even better games. Unity's main draw is its toolset to design beautiful 2D and 3D games which are easily portable to mobile platforms, making it the staple game engine for many mobile developers. As mobile hardware increases, so does the level of graphics being implemented into the games. However, there are still very strict limitations of mobile platforms vs. consoles. This article gives you some helpful tips for working more productively in Unity and ways to keep the level of detail in your games up while still cutting back on processing power.

Working with 3D Applications

As you may already be aware Unity doesn't have very powerful level or asset creation tools. The best workflow to take with Unity is to create all your assets and levels in a 3D application like Maya or 3ds Max. Luckily, Unity supports integration of just about every major 3D application, so you won't be hard-pressed to work in software you aren't comfortable with. Unity and other 3D applications are integrated nicely so the asset creation and modification can go much smoother. Scaling of assets can be done very easily. If you find the mesh you brought in is way too big you can go back to the file in your 3D application, scale it down to the correct size, save over the file and the asset in Unity will automatically get updated. As you start importing your meshes into Unity, a great workflow is to always import the texture first. Unity sees it's in there and, when the mesh is brought in, the texture will automatically get applied to the mesh. Of course, having to assign a texture back onto the mesh in Unity doesn't seem like a big problem, but finding places where you can speed up your workflow even just a little is always beneficial. 3D

Use Alpha Render Mode

The different render modes in Unity can be found in your scene view toolbar with the most common one being RGB. This allows you to see all of the colors and lights in your level. As you work you'll probably find yourself using this default one the most and maybe even exclusively. But it's important for you to know the other render modes and how they can help you optimize your game. For example, if you switch over to the Alpha render mode, it will change your entire level to white, meaning your game level is only displaying the alpha channel. This allows you to see areas that aren't completely closed off, like gaps in geometry or your level, which would be nearly impossible to see in the RGB render mode. Take for instance, if a section on your level isn't connected properly, it'll show up as a dotted black line, which stands out like a sore thumb in contrast to the white. The extra visibility allows you to go in and fix these issues very quickly.

Use Level of Detail

The level of detail feature inside of Unity is a great tool to use to that allows you take a very detailed asset and switch it out for a lower resolution mesh depending on how close the camera is. As the camera moves further away, it's going to switch out the mesh with the lower resolution version. This is a great optimization technique to use that can save a lot of processing time, because it only renders out the detail when it's actually necessary. There's no reason to display a high resolution of detail if the player isn't close enough to actually tell the difference. Of course, this will mean you'll need to model several versions of the same asset at different detail levels. You also need to keep in mind that this is a Unity Pro only feature. So if you're using the free version, it won't be available to you. Detail

Bake Lightmaps

As you start working with large levels requiring many different lights to create the look and feel you want, it can really start bogging down your game and have an impact on the framerate. To prevent your lights from impacting your game, you should be creating lightmaps. They allow you to bake all the lighting in your level directly to the actual textures. All of the lighting information stays there, but you don't need the lights anymore. You can also add things like ambient occlusion to a lightmap to enhance the realism, but keep in mind this will increase the bake time. Lightmaps may not be great for everything. Let's say you want to give the player the ability to shoot out a light. This wouldn't be achievable with a lightmap. So find places where you can implement lightmaps without hurting the gameplay.

Use Light Probes

Anytime you create lightmaps for the lighting in your game, you'll see it'll look great for all the static objects in the level, but it doesn't work for any type of dynamic asset in your game. This could be the character, enemies or anything moving. Dynamic objects will not be affected by the lightmaps. So while your level is nice and bright, the character will stay dark. Lightmapping can't be calculated for moving objects in real time, but it's possible to get a similar effect that you would get with dynamic lights by using light probes. By placing light probes in your level, it'll sample all of the lighting at each probe point. The lighting can then be interpolated between the samples taken from the nearest point. This can be done in real time so it simulates the lighting that would occur in the scene if there were actual dynamic lights set up and not lightmaps. When placing your light probes, you want to do it in areas with a high contrast in light. You'll also want to put a probe between two bright areas, so you'll get realistic results as your character moves through the level. Probes Next time you fire up Unity to work on your game project, find places where you can incorporate these tips to speed up your workflow and even cut back on processing time. To keep pushing your skills further check out our Unity tutorials, get an in-depth walkthrough on how to create a mobile game from scratch with this Unity Mobile Game Development Learning Path, and a series on Indie Game Development Pipeline.