LoadFromFile
Synchronously loads an AssetBundle from a file on disk.
Read time 3 minutesLast updated 6 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.AssetBundleModule
LoadFromFile(string)
Synchronously loads an AssetBundle from a file on disk.
public static AssetBundle LoadFromFile(string path)
Parameters
Path of the file on disk.
Returns
Type | Description |
|---|---|
| AssetBundle | Loaded AssetBundle object or null if failed. |
Remarks
The function supports bundles of any compression type. In case of LZMA compression, the file content will be fully decompressed into memory and loaded from there. See AssetBundles compression for more details.
Compared to AssetBundle.LoadFromFileAsync, this version is synchronous and will not return until it is done creating the AssetBundle object.
This is the fastest way to load an AssetBundle.
using UnityEngine;using System.Collections;using System.IO;public class LoadFromFileExample : MonoBehaviour{ void Start() { var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "myassetBundle")); if (myLoadedAssetBundle == null) { Debug.Log("Failed to load AssetBundle!"); return; } var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("MyObject"); Instantiate(prefab); myLoadedAssetBundle.Unload(false); }}
Additional Resources: AssetBundle, AssetBundle.LoadFromFileAsync.
LoadFromFile(string, uint)
Synchronously loads an AssetBundle from a file on disk.
public static AssetBundle LoadFromFile(string path, uint crc)
Parameters
Returns
Type | Description |
|---|---|
| AssetBundle | Loaded AssetBundle object or null if failed. |
Remarks
The function supports bundles of any compression type. In case of LZMA compression, the file content will be fully decompressed into memory and loaded from there. See AssetBundles compression for more details.
Compared to AssetBundle.LoadFromFileAsync, this version is synchronous and will not return until it is done creating the AssetBundle object.
This is the fastest way to load an AssetBundle.
using UnityEngine;using System.Collections;using System.IO;public class LoadFromFileExample : MonoBehaviour{ void Start() { var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "myassetBundle")); if (myLoadedAssetBundle == null) { Debug.Log("Failed to load AssetBundle!"); return; } var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("MyObject"); Instantiate(prefab); myLoadedAssetBundle.Unload(false); }}
Additional Resources: AssetBundle, AssetBundle.LoadFromFileAsync.
LoadFromFile(string, uint, ulong)
Synchronously loads an AssetBundle from a file on disk.
public static AssetBundle LoadFromFile(string path, uint crc, ulong offset)
Parameters
Path of the file on disk.
An optional CRC-32 checksum of the uncompressed content. If this is non-zero, then the content will be compared against the checksum before loading it, and give an error if it does not match.
An optional byte offset. This value specifies where to start reading the AssetBundle from.
Returns
Type | Description |
|---|---|
| AssetBundle | Loaded AssetBundle object or null if failed. |
Remarks
The function supports bundles of any compression type. In case of LZMA compression, the file content will be fully decompressed into memory and loaded from there. See AssetBundles compression for more details.
Compared to AssetBundle.LoadFromFileAsync, this version is synchronous and will not return until it is done creating the AssetBundle object.
This is the fastest way to load an AssetBundle.
using UnityEngine;using System.Collections;using System.IO;public class LoadFromFileExample : MonoBehaviour{ void Start() { var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "myassetBundle")); if (myLoadedAssetBundle == null) { Debug.Log("Failed to load AssetBundle!"); return; } var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("MyObject"); Instantiate(prefab); myLoadedAssetBundle.Unload(false); }}
Additional Resources: AssetBundle, AssetBundle.LoadFromFileAsync.