Skip to content

Instantly share code, notes, and snippets.

@crcdng
Last active August 2, 2020 21:05
Show Gist options
  • Select an option

  • Save crcdng/008b7a13da030a42bccb69755565d206 to your computer and use it in GitHub Desktop.

Select an option

Save crcdng/008b7a13da030a42bccb69755565d206 to your computer and use it in GitHub Desktop.
A few learnings from working with Unity3D https://unity.com/ (regularly updated)
### Unity3D tips
#### 1. Avoid creating instances in the game loop.
Unfortunately one of the first things you see in many Unity game tutorials is a mistake.
Wrong:
Correct:
Always create new Object
Create new instances in `Start()` instead and update its attributes in `Update()`.
If you need a variable amount of objects created on some agame event use an object pool. This
is the same principle. You create the objects in advance
https://learn.unity.com/project/c-survival-guide-object-pools?uv=2018.4&courseId=5cf06bd1edbc2a58d7fc3209
**TL;DR**: You should never see the `new` keyword inside `Update()`. Your garbage collector will thank you.
#### 2. Use [HideInInspector] to hide public properties.
If a property declaration to prevent the Inspector
from showing the property, even if it is public. C# contains attribute names within square brackets, like so:
```
```
Caveat: In other programming languages, "attribute" usually means the same as "property". In C# it is the annotation in square brackets.
Starting point to learn about attributes in Unity3D: https://docs.unity3d.com/Manual/Attributes.html
#### 3. Make the GitHub plugin work
GitHub for Unity is a plugin available on the Unity Asset Store that simplifies working with Git, Github and Git Large File Storage: https://assetstore.unity.com/packages/tools/version-control/github-for-unity-118069.
To make it work, set:
Edit > Project Settings > Editor > Version Control > Mode > Visible Meta Files
#### 4. Organize your Audio Mixer setup beforehand
Unity's built in audio system is quite flexible system, allowing Filters and Effects Audio Groups
Surprisingly, you cannot move Audio Groups between Audio Mixers for each Scene. Say, you started out with one Audio Mixer but later decide you want to have one Mixer per Scene. You cannot move your existing Audio Groups and therefore you would have to start from scratch (confirmed here: https://twitter.com/unity3d/status/1285162528226582528).
More information about audio in Unity: https://docs.unity3d.com/Manual/Audio.html
**TL;DR: If you use Unity's built in audio system, plan your Audio Mixer setup carefully beforehand.**
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment