Unity Tips Collection

By 09/11/2018 November 12th, 2019 General

Each Tuesday users post their tips about Unity to share shortcuts to all devs, improve the workflow and make things easier for everyone.
Here’s my Unity Tips collection; each week I make on tip and add it here.
You can follow me on twitter and you can join the list below to stay updated about all my posts and never miss anything.



Here’s a quick map of this post:

  1. Auto Statements in Visual Studio
  2. Shaders Introduction
  3. OnDrawGizmosSelected
  4. Second Parameter in Debug.Log
  5. String Interpolation
  6. Debug Break
  7. Tips about just starting learning
  8. Multi-line editing in Visual Studio
  9. Layer Locking
  10. TextArea
  11. Header, Tooltip and Space
  12. Extention Methods
  13. Platform Custom #defines
  14. Multiply Inspector’s editing speed
  15. Built-in shaders
  16. MinMax Attribute
  17. Animation Curves
  18. Un-dock the Preview window
  19. Hierarchy Organization
  20. Particle System Playback time
  21. EditorOnly tag
  22. Assign a shader to a material upon creation
  23. Insert array element in the Inspector
  24. Show the content of multiple folders
  25. Customize Unity’s C# template
  26. Console Window Log Entries
  27. OnValidate
  28. Set Editor Presets as Default
  29. Change the Editor color when it’s in Play Mode
  30. Drag/select scenes in the build settings
  31. Fold the entire Hierarchy
  32. Rich text in Unity’s console
  33. Asset Store search in project window
  34. DisallowMultipleComponent & RequireComponent
  35. Graphy
  36. Drag multiple items in the inspector
  37. Unity Visual Search
  38. NaughtyAttributes
  39. Foldout
  40. Scene Icons
  41. ContextMenu
  42. Inspector Math Expressions
  43. SerializeField & HideInInspector
  44. FormerlySerializedAs
  45. AddComponentMenu
  46. MenuItem

 


Auto Statements in Visual Studio

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


Shaders Introduction

You can now choose where to learn about Shaders in Unity!
My video and article are both available now.


OnDrawGizmosSelected

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


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.


Debug Break

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


Tips about just starting learning

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 it here on Twitter.


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.


TextArea

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


Header, Tooltip and Space

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


Extention Methods

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


Platform Custom #defines

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


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 archive download page.


MinMax Attribute

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

MinMaxAttribute.cs

MinMaxDrawer.cs



Animation Curves

You can use Animation Curves to create cool effects for your objects via code.
Read my tutorial about “Lerp/Easing” here.


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.

unity tips febucci organize hierarchy divisors organization unitytips tricks


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.

unitytips febucci shader assign automatically to a material upon creation


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.

insert array element unity inspector unitytips #unitytips febucci duplicate shortcut key


Show the content of multiple folders

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

unity febucci tips unitytips show content inside multiple folders 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#”.

change csharp c# template default unitytips febucci tutorial unity tips


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.

febucci console window log entries unitytips post #unitytips unity tips



OnValidate

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

unitytips post


Set Editor Presets as Default

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

unity presets default #unitytips 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 following code.
This way you’ll collapse all the GameObjects in the window with a simple click (mostly useful if you also add a keyboard shortcut).

Read more about the Hierarchy window and Unity Hotkeys.
Sources: Unity forum, Unity answers.

febucci unitytips unity fold entire hierarchy gameobjects


Rich text in the console

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


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.



Unity Visual Search

You can easily find 3D models for your game using Unity Visual Search and preview them in the Editor.
For example, it comes super handy if you’re building a prototype.

Asset Store page (it’s free).


NaughtyAttributes

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

GitHub repository here.


Foldout

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


Scene Icons

You can assign icons for GameObjects and Scripts.
Read more here.


ContextMenu

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


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 here: SerializeField and HideInInspector.


FormerlySerializedAs

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


AddComponentMenu

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


MenuItem

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 here.


That’s it for now, remember that I update this post each week, so stay tuned!

You can unsubscribe from the newsletter at any time, give it a try!

Support my current and future work ^^ As a thank, you will receive exclusive rewards!

Become a Patron!