Twitter Tips for Unity

Compilation of useful tips for Unity gathered from around Twitter.

The list below features various tips and tricks for Unity for the different areas, ranging from UI, Editor workflow, all the way to programming and level design.

1. Scene view GUI button

Do you want to display GUI elements in the Scene View to make development steps faster and easier? Add a static method of your choice to the "onSceneGUIDelegate" and draw everything you want.


2. .NET 4.x null-conditional operators

Switching to .NET 4.x in the player settings of your Unity projects gives you loads of neat C# 6 features! Here are my three favorites #unitytips
Null-conditional operators are great to avoid loads of extra code just to do sequential null checking

C# 6 features

3. DisallowMultipleComponent and RequireComponent

You can use the attributes "DisallowMultipleComponent" and "RequireComponent" to avoid setup errors in your game objects.

Sharp Coder Video Player

4. Menu item shortcuts

You can add keyboard shortcuts to your menu items in @unity3d.
Add % for Ctrl/Cmd, # for Shift, & for Alt before your hotkey. If you don't want a combination, adding underscore _ before your key will do.

Sharp Coder Video Player

5. Non-alloc collision contacts

WOAAAAAA!!! #Unity3d has no GC allocs for getting collision contacts anymore with a new "GetContacts(contactsBuffer)" method in 2018.3! Been waiting for this for ages. This is the only reason I need to expedite my move to 2018 now :)

6. SerializeField for editing private variables

Don't use the "public" access modifier just to edit a field from the Inspector. Use the [SerializeField] attribute instead.


7. Inspector lock

Did you know that you can drag multiple items in an array by locking the Inspector?

Sharp Coder Video Player

8. Object mirroring

Hey Lvl Designers! Wanna have a mirror object like this statue... Just change the scale to -1

9. Easy two-sided shader

Do you want two-sided materials but are too afraid to delve too deep into the dark art of shader coding? Just create a new standard surface shader and add the words "Cull off" after the "LOD" line. Works with unlit shaders too!

Sharp Coder Video Player

10. Run static method before or after scene load

There is a way to execute code in your scripts without having to create an empty GameObject with a MonoBehaviour. The "[RuntimeInitializeOnLoadMethod]" command allows you to execute methods before and after the scene loads. Useful to do some initialization and cleanup.