Unity Tips

by Federico Bellucci, 2018-09-03 | 22 minutes to read
Start using the best Unity tips I'm discovering during my game development journey since 2015. Improve your workflow and create your games faster. Inspector, Unity Editor, Scripts... Read more!

Start using the best Unity tips I’m discovering during my game development journey since 2015.

This Unity Tips collection has been created and updated by @febucci within these years and includes unity tips about Programming, the Unity Editor, Optimization, Games and way more!




Place 2D tiles automatically (RuleTile)

You can use Unity’s RuleTile script to automatically place tile combinations in your game.
–> Download 2D Extra Samples from Unity

P.S. Free tile assets provided by kenney.nl


Dialogue Box with Sprite Slicing

You can create a responsive Dialogue Box by modifying its “sprite slicing” settings.
(P.s. the text size is set to “Auto Size” and its anchor to “fill”).
Read more about Sprite Slicing.


Script Changes while Playing

You can set when to recompile your script changes (while playing) by going to Preferences->General.

unitytips unitytips febucci script recompile.jpg

OnDrawGizmosSelected

You can use OnDrawGizmosSelected() to see only your selected GameObjects’ debug.


Auto Statements in Visual Studio

You can auto complete statements in Visual Studio by pressing Tab twice.


Second Parameter in Debug.Log

You can use the second parameter in Debug.Log() to select your object from the console’s message.


String Interpolation

You can use String Interpolation to faster write strings with variables.

unitytips unitytips febucci string interpolation.jpg

Debug Break

You can use Debug.Break() to pause the Editor via script.


Tips about starting learning game dev

I’ve noticed that a lot of people I’ve talked to want to learn about game dev and Unity but don’t know where to start, which stops them completely. Here’s a thread with some of my (humble) learning game dev advices!
You can read my gamedev tips here.


Multi-line Editing (Visual Studio)

You can edit multiple lines in Visual Studio instead of copying and pasting each time.
It also works in VSCode and others, but the key shortcuts might be different.


Layer Locking

You can lock layers in the Editor to manage which objects to pick.


Header, Tooltip and Space

You can use the “Header”, “Tooltip” and “Space” attributes to better organize fields in the Inspector.


TextArea

You can use the “TextArea” attribute to edit a string in a flexible text area.


Extention Methods

You can use extension methods to add functionalities to already existing classes, types, structs and more!

unitytips unitytips febucci extension methods.jpg

Platform Custom #defines

You can set your own “Platform Custom #defines” to quickly add or remove features from your game’s build.
Read more about Platform dependant compilation.


Multiply Inspector’s editing speed

You can multiply the Inspector’s editing speed by pressing SHIFT (faster) or ALT (slower).


Built-in shaders

You can download all Unity’s built-in shaders (including all CGinc files) by visiting the Unity’s Archive download page.


MinMax Attribute

You can use the ‘MinMax’ attribute I wrote to better edit “random Vector2s” in the Inspector.


Animation Curves

You can use Animation Curves to create cool effects for your objects via code.
I have also written a tutorial about Lerp/Easing.


Un-dock the Preview window

You can un-dock the Preview window from the inspector and place it anywhere you want. (Right-Click on its top bar)


Hierarchy Organization

You can organize your Hierarchy by adding empty GameObjects as divisors.
I also suggest to set their tag to “EditorOnly”, so they’re not saved in the build.


Particle System Playback time

You can control the Particle’s playback time in the Editor to better edit effects.


EditorOnly tag

You can use the “EditorOnly” tag to exclude a GameObject from the final build.


Assign a shader to a material upon creation

You can create a material after clicking on the desired shader to assign it automatically.


Insert array element in the Inspector

You can insert an array element in the Inspector by pressing the key shortcut “CTRL/CMD + D” (which stands for: “Duplicate”), without having to adjust the next elements manually.


Show the content of multiple folders

You can see the content of multiple folders by selecting them in the Project Window.


Customize Unity’s C# template

You can customize Unity’s C# template by changing the “81-C#” file found in the path: “%EDITOR_PATH%\Data\Resources\ScriptTemplates”.
Remember to store a copy before modifying it!

You can find more info here.
P.S. when saving a copy of the original file, I recommend moving it into another folder or not naming it starting with “81-C#”.


Console Window Log Entries

You can adjust the number of lines shown for each Log in the Console Window, to read more (or less) text per entry.


OnValidate

You can make sure you entered the right value in the Inspector by helping you with the OnValidate function.
Read more about OnValidate


Set Editor Presets as Default

You can set Editor Presets as default and then apply them by pressing “Reset”.


Editor color in Play Mode

You can remind yourself that the Editor is in Play Mode by changing its “Playmode tint”.


Drag/select scenes in the build settings

You can drag multiple scenes in the build settings and enable/disable them at the same time (instead of one by one).


Fold the entire Hierarchy

You can fold the entire Hierarchy using the code linked below or by pressing ALT + left mouse click.
This way you’ll collapse all the GameObjects in the window with a simple click (mostly useful if you also add a keyboard shortcut).
Code here.


Rich text in the console

You can use rich text in Unity’s console.
Read more about Rich Text.

unitytips unitytips febucci rich text console.jpg

Asset store search in project window

You can search through the Asset Store directly from your project window.


DisallowMultipleComponent & RequireComponent

You can use the attributes DisallowMultipleComponent and RequireComponent to avoid setup errors in your gameObjects.
Read more about DisallowMultipleComponent and RequireComponent.


Graphy

You can monitor the performance of your games directly from your builds using this great tool made by @tayx94.
GitHub repository here.


Drag multiple items in the inspector

You can drag multiple items in an array by locking the Inspector.


NaughtyAttributes

You can use 20+ handy attributes made by dbrizov on GitHub, like a ReorderableList, a Slider or a ResizableTextArea.
GitHub repository here by dbryzov.


Foldout

You can group variables in the Inspector using the Foldout attribute, made by dimmpixeye on GitHub.
GitHub repository here by PixeyeHQ.


Scene Icons

You can assign icons for GameObjects and Scripts.
Read more about Assignign Icons.


ContextMenu

Call methods from the Inspector by using the ContextMenu attribute.
Read more about ContextMenu.


Inspector Math Expressions

You can enter math expressions in the Inspector.


SerializeField & HideInInspector

Choose which variable to show and serialize by using the attributes SerializeField and HideInInspector.
Read more about: SerializeField and HideInInspector


FormerlySerializedAs

Useful if you need to rename a variable without losing its serialized value.
Read more about FormerlySerializedAs attribute.


AddComponentMenu

Organize your scripts in the “AddComponent” Menu in the Inspector by using the AddComponentMenu attribute.
Read more about AddComponent.


Call methods from the Main Menu and Inspector Context Menus. Be aware that it only works in the Editor, so you need to cut it if you want to release that code. (Add #if UNITY_EDITOR and you’re good to go).
Read more about MenuItems.



Share this article ❤ on: X (Twitter) Facebook

Did you like this post?

Read our next game dev content as soon as it's ready, straight to your inbox. (you can unsubscribe at any time.)


Latest articles