Chapter 8. Tactical Tips and Tricks

There are a lot of little nuances to using the Unity Engine that can help improve our project workflow. However, quite a lot of the Editor's functionality is not well documented, well known, or just not something we think about until after the fact that it could have been applied perfectly to solve a particular problem we were having 6 months ago.

The Internet is crammed full of blogs and forum posts that try to help other Unity developers learn about these useful features, but they only tend to focus on a handful of tips at a time. There don't seem to be any online resources that group together many of them in one place. As a result, intermediate and advanced users probably have bookmarked managers bursting at the seams with links to these tips that they run into at one point or another, but which sit and rot until it comes time to do some spring cleaning.

So, because this book is primarily for intermediate and advanced users, it felt like it was worth throwing in a short chapter to bring tons of these tips and tricks together in one location. It works as a reference list in the hope of saving us a lot of future development effort.

Editor hotkey tips

The Editor is rife with hotkeys that can aid rapid development. It's worth checking out the documentation. But let's be honest, nobody reads the manual until they need something from it. Here are some of the most useful, yet lesser-known hotkeys available when playing with the Unity Editor.

Note

In all cases, the Windows hotkey is listed. If the OSX hotkey requires a different set of keystrokes, then it will be shown in parentheses.

GameObjects

GameObjects can be duplicated by selecting them in the hierarchy and pressing Ctrl + D (Cmd + D).

New, empty GameObjects can be created using Ctrl + Shift + N (Cmd + Shift + N).

Press Ctrl + Shift + A (Cmd + Shift + A) to quickly open the Add Component menu. From there, you can type in the name of the Component you wish to add.

Scene View

Pressing Shift + F or double-tapping the F key will follow an object in the Scene View, which can be helpful for tracking high-velocity objects or figuring out why objects might be falling out of our Scene.

Holding Alt and left-click dragging with the mouse will make the Scene View camera orbit the currently selected object (as opposed to looking around it). Holding Alt and right-click dragging will zoom the camera in/out.

Holding Ctrl and left-click dragging will cause the selected object to snap to the grid as it moves. The same can be done for rotation by holding Ctrl as we adjust the rotation widgets around the object. Selecting Edit | Snap Settingsā€¦ opens a window where we can edit the grid that objects snap to on a per-axis basis.

We can force objects to snap by vertex, holding the V key as we move the object around. The selected object will attach itself to the nearest vertex, to the cursor of the nearest object. This is very useful for aligning level pieces into place, such as platforms and other tile-based systems, without needing to hand-adjust position vectors.

Note

At one point, in Unity versions 4.2 to 4.6, it was possible to hold Shift with a Collider object selected to reveal little hooks through which we could adjust the Collider through the Scene View. This was removed in recent versions of Unity due to conflicts with other controls. We must use the Edit Collider button within the Collider component to access this feature going forward.

Arrays

We can duplicate array elements that have been exposed in the Inspector View by selecting them and pressing Ctrl + D (Cmd + D). This will copy the element and insert it into the array immediately after the current selection.

We can remove entries from an array of references (for example, an array of GameObjects) by pressing Shift + Delete (Cmd + Delete). This will strip away the element and condense the array. Note that the first press will clear the reference setting it to null, but the second press will remove the element. Removing elements in arrays of primitive types (ints, floats, and so forth) can be accomplished by simply pressing Delete without the Shift key (Cmd) modifier.

We can use the W, A, S, D keys while right-click dragging on the Scene View to fly around with the camera, in a typical first-person camera control style. The Q and E keys can be used to translate the camera on the vertical axis, respectively.

Interface

We can hold Alt and click on any hierarchy arrow (the small grey arrow to the left of any parent object name) to expand the object's full hierarchy and not just the next layer. This works on GameObjects in the Hierarchy View, folders and Prefabs within the Project View, lists in the Inspector View, and so on.

We can save and restore selections from objects in the Hierarchy or Project Views in typical RTS game style! Make the selection and press Ctrl + Alt + <0-9> (Cmd + Alt + <0-9>) to save the selection. Press Ctrl + Shift + <0-9> (Cmd + Shift + <0-9>) to restore it. This is exceptionally useful if we find ourselves selecting the same handful of objects over and over again while we make adjustments.

Pressing Shift + Spacebar will expand the current window to fill the entire Editor screen. Pressing it again will shrink the window and restore it to its previous location.

Pressing Ctrl + Shift + P (Cmd + Shift + P) will toggle the Pause button while in Play Mode.

Other

We can quickly access the documentation of any Unity keyword or class, by highlighting it in MonoDevelop and pressing Ctrl + ' (Cmd + '). This will open the default browser and perform a search on the Unity documentation for the given keyword or class.

Tip

Note that users with European keyboards may also need to hold down the Shift key.

With the recent release of Visual Studio Tools for Unity (VSTU), it is possible to access the documentation in the same way through Visual Studio by pressing Ctrl + Alt + M, followed by Ctrl + H (no equivalent OSX hotkey, obviously).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.184.3