Asset bundle
- Game Development course
- Expert
- Lesson 11/47
- 4 min
Learn to load large assets in chunks with AssetBundle.
What is AssetBundle?
An AssetBundle is a structure that carries game assets in a single package file. Instead of loading large assets all at once at the start of the game, you can load them part by part with AssetBundles. This way the amount of data held in memory at one time decreases.
AssetBundle paket = AssetBundle.LoadFromFile("dolap");The package is opened and used as the assets are needed.
Streaming
Streaming is loading assets as a stream and only when they are needed. A section the player will not see right away can be loaded later. This way both loading time and memory load are shared.
string paketAdi = "SahneVarligi";
int parcaSayisi = 3;Loading in parts is essential for large games.
Practice Keep a package record
In a class named VarlikYukleme, define a string field named paketAdi with the value "SahneVarligi" and an integer field named parcaSayisi with the value 3. In the Start method print the pieces "Paket: ", paketAdi, " Parca: " and parcaSayisi joined together with Debug.Log.
Starter code
using UnityEngine;
public class VarlikYukleme : MonoBehaviour
{
// paketAdi adli metin alanini "SahneVarligi", parcaSayisi adli tam sayi alanini 3 degeriyle tanimla
void Start()
{
// "Paket: " + paketAdi + " Parca: " + parcaSayisi biciminde yazdir
}
}Sample solution
using UnityEngine;
public class VarlikYukleme : MonoBehaviour
{
string paketAdi = "SahneVarligi";
int parcaSayisi = 3;
void Start()
{
Debug.Log("Paket: " + paketAdi + " Parca: " + parcaSayisi);
}
}Expected output
Paket: SahneVarligi Parca: 3
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What is the main purpose of using AssetBundles?
- To load all assets at once at the start of the game
- To speed up light calculations during the game
- To compile C# files
- To load large assets in parts when needed Correct answer
Explanation: An AssetBundle splits large data; this way all assets are not loaded into memory at once.
2 Load the package from file
AssetBundle.____("dolap");
AssetBundle.LoadFromFile("dolap");
Explanation: AssetBundle.LoadFromFile loads the package file from disk; this method is used instead of a needless full load.
3 AssetBundle terms
| Term | Meaning |
|---|---|
AssetBundle |
The package file that carries assets |
Parça parça yükleme |
Bringing large assets in parts |
Streaming |
Loading as a stream when needed |
Bellek yükü |
The amount of data carried at one time |