My General Tips for Unity

 

HOW TO BE A PRO

 

Now that Professional(Dark) theme is available for us mortals, the first action in your Unity window should be Edit->Preferences->General->Edit Theme: Change to Professional. Now you can be a professional without paying hundreds of $/month.

 

 

RECOMPILE ME NOW

 

While you are there, this next one depends on your personal preference and may be a bit advanced, but I usually make project in a way that when scripts recompile and scene gets Serialized and then Desterilized back, the project keeps working correctly where I left off. So Script Changes While Playing is Recompile And Continue Playing for me. 

 

CHANGE THE SCRIPT

 

A small detail many don't know is that if you want to replace a script with a similar script, you can do it by clicking with right mouse button on the tab name (Inspector) and setting it to Debug. Changing script this way will preserve all the serialized fields.

 

 

UPDATE ME LATER

 

For UI and every complex system in the game I assume the worst case scenario: the data they show may update many times during some frames. So I use LateUpdate() function to update UI once after all the information that could change, changed. To make sure I do it only when needed, I use versioning. Data has a version and UI Controllers remember, which version of Data they are showing. This also means that when UI is disabled and doesn't run it's LateUpdate(), it will only do it when it gets enabled again and sees that it's version is not the same as version of the data they are supposed to be representing.

 

 

TEACH TMP HOW TO DEFAULT

 

Talking about UI. If you are using Text Mesh Pro (which you should, it is better) find TMPSettings Scriptable Object and configure it:

  • Set your default font

  • Disable Raycast Target

 

 

WRAP THAT INDEX

 

Here are some examples of a problem:

 

GetPlayerWeapon(int index) { }

GetPlayerArmor(int armorIndex){ }

GetPlayerArmorStat(int statIndex) {}

 

It is not hard to imagine a call to a function that looks like this:

 

var stat = GetPlayerArmorStat(armorIndex);

 

Which has an error, we sent armor index instead of stat index. And things can get even more messy when you are working with many different indexes and ids. Items can have Prototypes(contains values that don't change, like Type, Max Durability) and States(values that are unique to each item, like Current Durability, Upgrades).

 

Proper naming can save you from logical mistakes, but there is still room for mechanical ones. 

 

To avoid any confusion instead of:

 

GetPlayerArmor(int armorIndex){ }

 

I will have:

 

GetPlayerArmor(ArmorIndex armorIndex){ }

 

where 

 

struct ArmorIndex  

{

int index;

}

 

Yeah, it does look like a lot of work, but makes life much easier. Especially when you can do cool stuff like this:

 

var armorState = player[armorIndex];

var weaponState = player[weaponIndex];

 

by placing the following syntaxes into the character class:

 

ArmorState this[ArmorIndex i] => _armorStates[i.index];

 

May look excessive to some. Totally understandable. But it becomes almost impossible to request something by the wrong index. Lets me sleep better.

 

 

LET ME HEAR IT PLAY

 

While most early prototypes are very quiet, sound can be very useful from the very start of the development. For example: if button didn't work but the click sound played, you can be sure that the function was called and button itself works correctly. Same for hits, impacts. The sound will always let you know if code executed to a certain point.

 

 

UNDERSCORE YOUR PROJECT

 

Create a _PROJECT folder in your Assets and put all your stuff there. You are likely to pull more things from Asset store into your Assets folder, so having the project in its own is better. I tried to have a folder called ThirdPartyAssets and put all Asset store stuff in there, but it was a loosing battle, many things went wrong. Better to just give up and give them the root of the Assets folder and use _PROJECT for yourself. The underscore is needed to make sure it stays on the top.

 

 

CONTEXT FIRST

 

Organizing your assets by Context, not by type. You are likely to have a folder called Materials early on. But if you get a model of a character with it's own Materials, Textures, Scripts, Animations maybe even Shaders, it would be a bad idea to break it apart into separate folders and mix Character Materials with UI Materials. So I have a rule: Context - first, Type - second. For Example:

 

_PROJECT

     _MainMenu

        Scripts

        Sprites

        Materials

     _Player Screen

        _Skill Window

             Scripts

               Scriptable Objects

               Prefabs

        _Quests Window

           Scripts

                   Data

                   View

        Scripts      // For Player Screen in general

        Textures    // For Player Screen in general

     Scripts        // For _Project in general

     Materials     // For _Project in general

     Shaders      // For _Project in general

 

The last Scripts, Materials and Shaders folder contains things that I use all throughout the project. Just like there are scripts that manage Player Screen, but Skill Window has it's own stuff.

 

 

 

NAME THEM RIGHT

 

If I instantiate a bunch of object, like default NPCs and then assign to them the correct outfit and face, I will also change gameObject.name so that in Hierarchy view (where you can see all the stuff in your scene) I can easily find them. So instead of Character(Instance) I will see Bob.

 

 

SPEED IT UP

 

There is a Time.timeScale parameter that can be used to speed up/slow down your game. I always expose it to myself in some way: be it a slider or just pressing some button on the keyboard. Whenever testing the game you want to skip long animations or slow it down if something about it feels off.

Please reload

Social:
Facebook icon
unnamed.png
Instagram icon
Geeky:
GitHub icon
unity-Connet-Logo.png
Discord icon