Resources

Installation

Note
I’m a Linux user so I’m only dealing with Linux. If you have issues involving other platforms then you are unlucky to not be using Linux but lucky that you’re not alone and there are tons of adequate resources to help you out.

In 2018 on the Unity download page there are Mac and Windows versions mentioned but no Linux. Hmmm. Fortunately, on this hidden forum page release notes for a Linux version are discussed. The latest (2019-02-15) release notes confirm that there is definitely a Linux version. And it looks like there’s an even more up to date version now.

2022-04-30 - Wow, this is complicated to find. It looks like right now the LTS version of Unity is 2021.3.0. The general download site seems to be: https://unity3d.com/unity/whats-new/2021.3.0 The specific link to wget is: https://download.unity3d.com/download_unity/6eacc8284459/LinuxEditorInstaller/Unity.tar.xz

If you change to the (questionably named) ./Editor directory where all that unpacks to, you can run ./Unity. And then you’ll get an error "No valid Unity Editor license found. Please activate your license!" Ok, how do I do that? This says to "Launch the Unity Hub." Ok, how do I do that? Read on…

On 2018-08-28 it says "Unity Hub is not available for testing on Linux yet." But shortly thereafter on 2018-12-18 it is changed to "Note that Unity Hub is now the preferred way to install Unity for Linux."

So what’s this "Unity Hub"? Here is an official answer: "The Unity Hub is a standalone application that streamlines the way you find, download, and manage your Unity Projects and installations." Ok. Here is where you can get it. (Still there just like that, 2019-11-10.) Specifically, wget it from (as of 2022-04-30):

Got it. Now WTF is an "AppImage"? According to the file command it is a ELF 64-bit LSB executable. Ok, so make it executable and run it.

$ chmod 755 UnityHubSetup.AppImage && ./UnityHubSetup.AppImage
  • Click the "Agree" box swearing allegiance to this feudal lord.

  • I declined having it "integrate" into my system.

  • In the upper right corner, you can "sign in" and I did make an account already. Or…

  • Create an account in the usual annoying way.

  • Choose "Activate New License"

  • Choose "Unity Personal" if you haven’t paid any money for this.

Ok, so that’s actually from the settings icon (upper right), hit the left arrow icon (upper left) to go to the main menu. From here you can start new projects and such.

Editor

Obviously you’ll want to use a good editor. Unity3dVim seems sensible. But the problem is that Debian Vim isn’t compiled with the proper server hookup. I replaced his VimRunner.sh script with this simple one that did the job.

#!/bin/bash
/usr/bin/mate-terminal --command="/usr/bin/vim +${L} \"$1\""

Shortcuts

  • Q,W,E,R,T - swap between tools.

  • [C] + Move operation - snaps position to full world units.

  • [C] + [S] + Move operation - snaps position to collision. ?

  • [C] + [S] + Rotate operation - orients object to mouse cursor. ?

  • V - (hold to) move and position and align objects by their vertices.

  • [C] + D - Duplicate and object.

Coordinates

Unity coordinates use something like the Minecraft coordinate system — +X is west (+90deg), +Y is up, +Z is south (0deg). Of course you can make north anything (or anything anything really) but +Y is going to want to be up.

Physics

"Rigidbody" components are positioned by the physics engine. If you want them to be scripted independently but still available to activate "triggers", you can set the "Is Kinematic" property.

Rigidbody objects are updated if they are in motion. If they come to rest, the engine stops worrying about their physics until they are hit with a new force. These untracked objects are said to be "sleeping".

One adds forces to rigidbodies with something like rigidbody.AddForce() and the physics engine calculates how that turns out.

PhysicsUpdateRate controls how frequently the physics engine does calculations. Changing from default .02 to .04 will halve the calculation frequency and allow a lot more to transpire.

Math

Vector3.magnitude() involves a sqrt. Vector3.sqrMagnitude much cheaper.

If checking distance ranges…

if (Vector3.Distance(pointA,pointB) < mindist) { // do something }

…do something like this…

if ((pointA-pointB).sqrMagnitude < mindist * mindist) { // do something }

…which saves an expensive square root operation.

Objects

More technically, I believe they are called "GameObjects" in Unity. GameObjects are embellished with "components" which add functionality to them. Add components in the (highlighted) object inspector window at the bottom.

GameObjects with a particular configuration of components and settings can be replicated by making them into a "Prefab".

To copy an object you can use the Instantiate(existingObject) function.

To loop over all children of an object use something like this.

foreach (Transform child in transform){ Debug.Log(child.name); }

Game Flow

Here is a nice summary of all the functions that are called in the game loop. Physics, input, game logic, scene rendering, GUI rendering, etc. It also covers the order that the scenes (or maybe levels in game userspace) are loaded. And things like OnApplicationQuit for cleanup.

Events

  • OnGUI() - Gets called sometimes to deal with GUI matters.

  • OnCollisionEnter(other) - Check if a collision has started happening.

  • OnCollisionStay(other) - Check if a collision is happening.

  • OnCollisionExit(other) - Check if a collision stopped happening.

  • OnTriggerEnter(other) - Like OnCollisionEnter but no physical responses. Like a simple check for when a game object enters a special zone.

  • OnTriggerStay(other) - Similar.

  • OnTriggerExit(other) - Similar.

Time And Delta

To accommodate variable speeds of the frame updates, calculations that want to be done at a certain rate with respect to wall clock time must be anchored on Time.deltaTime.

degreesPerSecond * Time.deltaTime

You can slow or speed time and other tricks with the Time.timeScale property. Setting it to 0 would cause the game action to pause. Setting it to 1 moves time normally.

GUI

There are some ways to decorate variables such that they show up more helpfully in the inspector.

  • [Tooltip("This text will appear when hovering.")]

  • [Range(0f,10f)] - Slider.

  • [Space] - Adds empty space.

  • [Header("Simulation Settings")] - Adds a heading label.

Profiler

See the "Deep Profiler". Good to know what’s taking all the CPU and memory resources.

Debug

The drop down menu at the top of the inspector has a "Debug" mode.

Debug.Log("<color=red>Red text here</color>" + " and normal text here.");

Debug text values not making things clear? Need to see a nice graphical plot of some variable in action? Add this to the public class section to use the AnimationCurve functionality to show a running plot of a variable.

public AnimationCurve plot = new AnimationCurve;
void Update() {
    float value= Mathf.Sin(Time.time);
    plot.AddKey(Time.realtimeSinceStartup,value);
}

To pause at some script defined point in the simulation.

EditorApplication.isPaused= true;

There is a game statistics window and a profiler window. To force a particular game calculation to be profiled explicitly, set it up with this.

using UnityEngine.Profiling;
...
Profiler.BeginSample("expensive");
SomeCalculation();
Profiler.EndSample();

Frame debugger will show how each frame is rendered (i.e. the order).

There is also a physics debugger — maybe useful for catching collider errors.

There is also a lightweight diagnostic tool called miniprofiler which seems less intrusive than the full Unity one.