Game Graduate

Your Game Guru

Unity Questions & Answers [Ultimate Guide]

Unity logo used as featured image for the post of Unity Questions & Answers [Ultimate Guide]

Hello everyone! Today we will start a new post: Unity QA. This post will shape by your contributions and my experiences. I will get help from obstacles that I encounter while using Unity; then provide solutions to them. While saying your contributions, I mean you can ask your very own questions or share your opinions! It can be anything like even “what is Unity?”. So, let’s start!

Call To Action!

This content will be kept up-to-date! Meet me in the comments to share your opinions and your very own questions! If you want to read more posts like this one, don’t forget to look at the Ultimate Guide and Technical Spot of Games categories!

Are you an Unreal developer? Then, you may like Unreal Engine Questions & Answers!


1. What is FixedUpdate()?

Okay, this function helps you to overcome fps differences across different consoles. In other words, this function is a version of the Update() function that works in fixed time intervals. It is an fps-independent function. Why do we need this kind of function? For example, if you try to write every movement code in the Update() function; then you will see unexpected behavior in different PCs. For example: if you have a high-end pc, you can get 144fps which means the Update() function will work 144 times in one second. If one of the players has a low-end pc, s/he has 30fps which also means 30 times in a second! Then now assume that you are playing with this player online. You may imagine the chaos of a jet-speed player, right? 🙂

In short, if you want all players to have the same function executing in the same time intervals; then FixedUpdate() is your solution.

2. How to get random number on each execution of RandomRange()? I always get same “random” number!

It is a common problem that new unity developers generally face. When you execute Random.Range() function over and over, you always get the same number. How is it even random if you get the same number every time?

It has a simple explanation: seed. Try to think of the source of randomness as a plant. If you keep giving the same seed to the earth, you always get the same crop.

The point in the sequence where a particular run of pseudo-random values begins is selected using an integer called the seed value.

Random.InitState() Manual

As you see, roughly, when you change the seed; you also change the starting point of randomness choice.

Random.InitState() Example with the altered seed. Used in the post of Unity Questions & Answers [Ultimate Guide]
Random.InitState() Example with the altered seed
int seed = (System.DateTime.Now.Millisecond + System.DateTime.Today.Minute) * 04021995;
Random.InitState(seed);

SpawnRandomObject(5);

Further Read: Random.InitState Manual & Random.Range Manual

3. Can I create a project specialized for mobile devices?

Yes, indeed! You can create your own chosen project type in the project creation menu. There are lots of other templates that are available to download. Once downloaded, you can use one of these templates as your project’s base.

unity project templates
Templates that are available for a New Project

4. How can I test my game with my own android phone?

Yes, you can test your mobile games with your device. Moreover, you don’t have to build your game before testing it with your mobile device! Let’s look at the steps required for it:

Step 1. Adjust your mobile device’s settings

First things first, start with the required settings for your mobile device. To set required settings, go to:

Required step before starting!

First of all, be sure that you enabled Developer Options of your device. If you have a Samsung device, you can follow this link to enable it: How do I turn on the Developer Options menu on my Samsung Galaxy device?

Settings -> Developer Options -> and set USB Debugging ON

developer options of samsung device
Set USB Debugging ON in Developer Options

Step 2. Install Unity Remote 5 from Google Play Store to your mobile device

Unity Technologies has a worthy application to test your games without building them. In this required step, you should install Unity Remote 5 on your mobile device.

unity remote 5 google play store page
Google Play Store page of Unity Remote 5

Step 3. Connect your phone to your computer via USB cable

Before opening Unite Engine, I recommend you plug your mobile device in first. I encounter that Unity cannot recognize your mobile device if you plug in your device after opening the editor. In case of that Unity cannot recognize your device, remember to repeat this step.

Step 4. Set your project’s target platform to Android

You can do this in Unity Hub’s project selection window. Alternatively, you can do this via File -> Build Settings… -> Set platform as Android and click Switch Platform.

build settings of project
Set platform as Android

You can confirm your current platform by looking top left corner of the project window:

top left of unity window
Android is the current platform of this project

Step 5. Change Unity Remote Device of Unity engine

In this step, we will simply tell Unity to use any android device available. By choosing this option, we will be able to establish communication between our computer and mobile device.

Edit -> Project Settings… -> Set Unity Remote Device to Any Android Device

unity remote device options
Set Unity Remote Device to Any Android Device

Step 6. Play the game!

Open the Unity Remote 5 application from your mobile phone. Then press the play button from your Unity project. The game screen synchronizes with your phone screen as it should be. You can now give inputs via your mobile phone.

4-1. Unity Engine does not recognize my phone! What should I do?

It depends on what your error is. Let’s see a possible action for one error:

4-1-1. error: device offline

This error may occur since you are using a damaged or not-proper USB port of your computer. Try changing your USB port, and play again.

error: device offline
error: device offline