Hello.
I am having a problem trying to get an image with dragon bones using an asset bundle.
First, I need to get two files, DragonBonesAsset and DragonBonesAtlasAsset.
In other words, we need the following two variables
let bonesAsset: dragonBones.DragonBonesAsset;
let atlasAsset: dragonBones.DragonBonesAtlasAsset;
Then, retrieve the two files and set them in the dragonborn’s armatureDisplay as follows
const bonesAsset = await this.assetBundle.loadFile<dragonBones.DragonBonesAsset>(
'BundleTEST',
filePath + '_ske'
);
atlasAsset = await this.assetBundle.loadFile<dragonBones.DragonBonesAtlasAsset>(
'BundleTEST',
filePath + '_tex'
);
console.log(bonesAsset);
console.log(atlasAsset);
if (atlasAsset === null) {
console.log('atlasAsset IS NULL'!!!);
}
this.armatureDisplay.dragonAsset = bonesAsset;
this.armatureDisplay.dragonAtlasAsset = atlasAsset;
As a test, we run this process with dragonbone material for 5 characters in a bundle named BundleTEST.
Here, both bonesAsset and atlasAsset are displayed correctly and some characters are displayed, while others cannot be displayed because atlasAsset is empty.
If you check the log, you will see the following.
On the left in this screenshot is the normal case,
DragonBonesAsset(ske) and DragonBonesAtlasAsset(tex), but in the right case
DragonBonesAsset(ske) is obtained, but DragonBonesAtlasAsset(tex) is not. However, it does not seem to be null or empty.
The code to read a file from an asset bundle is as follows
There are no errors logged in this code or any logs that indicate that the reading fails.
async loadFile<T extends Asset>(bundleName: string, fileName: string): Promise<T> {
try {
const bundle = await this.loadAssetBundle(bundleName);
return await new Promise<T>((resolve, reject) => {
bundle.load(fileName, (err: Error | null, asset: T) => {
if (err) {
this.errorLog(`Failed to load the file: ${fileName}`, err);
reject(err);
return;
}
console.log('SUCESS ' + fileName, bundle);
resolve(asset);
});
});
} catch (err) {
this.errorLog(`Failed to load the bundle: ${bundleName}`, err);
return Promise.reject(`Failed to load the bundle: ${bundleName}`);
}
}
async loadAssetBundle(bundleName: string): Promise<AssetManager.Bundle> {
return await new Promise((resolve, reject) => {
assetManager.loadBundle(bundleName, (err: Error | null, bundle: AssetManager.Bundle) => {
if (err) {
this.errorLog(`Failed to load the bundle: ${bundleName}`, err);
reject(err);
return;
}
this.bundleLog(`Success to load the bundle: ${bundleName}`, bundle);
resolve(bundle);
});
});
}
This issue is very tricky.
If the file paths, etc. are wrong, I would get an error such as null, but that is not the case, just that certain files are empty, which is very troubling.
I am using only one bundle, DragonBonesAsset and DragonBonesAtlasAsset, which have separate folders for each character, and there are no files missing.
Any solutions or super methods for this?