- Home /
How to calculate CRC from a bundle file?
I am trying to use the method GetCRCForAssetBundle and according to the documentation it should provide the CRC given a bundle path. Code below, ive double checked the file path is correct etc, maybe im doing something wrong?
This method gives no exception or explanation it just keeps returning false. Does it only work on a certain type of bundle?
For bonus points, this appears to not be CRC32 am i correct in assuming its something custom they've done.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
public class test : MonoBehaviour {
// Use this for initialization
void Start () {
Debug.Log("Started");
var path = @"C:\Test\Build\Bundle.unity3d";
uint crc;
BuildPipeline.GetCRCForAssetBundle(path, out crc);
Debug.Log(crc);
}
// Update is called once per frame
void Update () {
}
}
Are you positive that you can use an absolute path? $$anonymous$$any times in Unity, a path must be relative to the project or the compiled data. If you CAN use an absolute path, the application would need permission to read that file. Depending on your Windows version, this can be trickier than just making sure your own Windows user has permissions.
Answer by FlaSh-G · Sep 06, 2017 at 11:05 AM
Whenever a Unity method wants a path, it usually has to be forward slashes relative to your project root. So you can pass "AssetBundles/Bundle"
if the actual OS path is projectRoot + @"AssetBundles\Bundle.unity3d"
.
Answer by PW_Dave · Nov 07, 2017 at 12:03 AM
BuildPipeline.GetCRCForAssetBundle(targetPath, out crc) gets the CRC value from the manifest file that is generated with the bundle, i.e. targetPath + ".manifest". In fact, if you have the CRC: # line in the manifest file, and no bundle file at all, you'll get the crc value back. If the manifest file exists, but the data is incorrectly formatted, you'll get a crc of 0. If the manifest file is not found, then it returns false.
Your answer
