Cheat to Win: Shortcutting Your Unity Workflow
Published a year ago
Helpful tips and tools for streamlining your Unity debug workflow, with a VR twist.
One of the things I've learned while developing games is the importance of creating useful cheats and debug tools. It's a huge timesaver to jump straight to the part of the game you're working on. We've used a number of cheats and debug tools while developing our Gear VR puzzle game, Hidden Fortune. Unity has a lot of great features that help with debugging; running the game in the editor, saving debug buttons as prefabs for quickly adding to a scene, and creating custom editor scripts can all improve your working process in different ways.

Editor Debugging

For a VR game, it's crucial to make the game playable in the editor. This helps if you don't always have enough headsets to go around, and it's also much faster to check things in the editor instead of making a build and putting the headset on. First, you'll need a script that moves the camera's facing direction as you move the mouse. Attach it to the camera rig. (The same game object that has the "OVR Camera Rig" script.) I prefer to have the script only move the camera when I press the left Alt key, but you can have the mouse move the camera all the time if you prefer. (We use this script here.)
The Gear VR touchpad is configured to act like a mouse, so you should be able to play in the editor by using mouse movement and clicks.
  • Tip: if you’re using the Gear VR controller, you can use a mouselook script to rotate your controller object with the mouse.
Hidden Fortune offers a ton of quests for players to beat. Each quest begins with a few lines of helpful dialogue from an NPC, followed by the game itself. For testing, it's great to have a keyboard key that skips the dialog and another one to instantly win the game. When you’re testing your project, look out for things that you find yourself doing repeatedly, especially if those things take some time to complete. This is a golden opportunity to add a cheat key.
Another example is this script, which keeps a list of teleport points and then lets you move between them by pressing T. It’s faster than teleporting in the game normally, so it’s convenient for testing.
Unity’s custom editor windows are really useful for stuff that you might want to do in between games, such as setting the player's experience level, clearing your save data, or configuring your character. By using buttons on an editor panel to do things during gameplay, you can avoid cluttering; we also display some information about our character’s progress on the debug panel.
Don’t forget to periodically evaluate the debug buttons: as development progresses, you may find that some buttons are no longer useful or other features need to be added.
Some of the buttons and information on our debug panel don’t make sense if the game isn’t running. Instead of doing nothing or showing an error message when you press the button, we actually disabled the buttons if Application.isPlaying is false. That way, team members who aren’t as familiar with that functionality don’t get confused.
Visualization aids are another thing that Unity is good at. Need to see what’s happening with a vector? Take advantage of Unity’s Debug.DrawLine or Debug.DrawRay functions. Need to see where something happened? Use GameObject.CreatePrimitive to mark the position with a small sphere.
  • Tip: You can prevent your debug displays from being included in the builds you make by having your code only run if Application.isEditor is true.

Testing on a Device

When you're testing on a device where you don’t have buttons that can be used as debug keys, there are still various things you can do to help you debug. One method we use is to place buttons in the scene. This is easy to do if you have a plain button asset that you can drop into the level easily. At various times, we've had debug buttons to clear saved data, level up the player, or go to a test level.
For debugging certain types of problems, a textbox placed in the scene is also incredibly helpful. We use this most often for checking the frame rate when running on device. It lets us simply look around the scene to find out where the problem areas are.
  • Tip: For problems that are hard to reproduce in the editor, try writing a script to output log messages to a textbox in the scene, so you can see the log output while playing the game. You can monitor log messages using this callback here.
Don’t forget to remove your debug buttons and displays before releasing the game! To be really safe about this, write a script that deletes its game object if Debug.isDebugBuild is false, and attach that script to all of your debug displays.

In Conclusion...

A small amount of time invested in debug keys or custom editor panels can save you enormous amounts of time over the course of the project. It will also save your sanity as you can avoid reading the same dialog or playing the same games over and over and over and over...
Remember, the cheats are there to support your needs and the needs of your team. Change the cheats as the game changes! For example, if you’re making a shooter, you might want buttons to level up your character and unlock new weapons, or a debug key to reduce the ammunition in your weapon to make sure it behaves correctly when you use the last shot.
  • Tip: Talk to other members of your team regularly. Is there a tedious process that could be automated with an editor script? Are there values the designers need to tune that could be exposed in the editor? Maybe there’s a debug button you haven’t thought of that the artists would find useful.
In conclusion, debug keys are essential for speeding up your game development process. Just remember, players who cheat never win, but developers who don’t cheat always lose.
Renee Klint
Community Manager - Writer