Monday, March 3, 2025
spot_img

Asset bundle can’t be loaded – Cocos Creator


Hi there.
I’m having an issue making an attempt to get a picture with dragon bones utilizing an asset bundle.

First, I must get two recordsdata, DragonBonesAsset and DragonBonesAtlasAsset.
In different phrases, we want the next two variables

let bonesAsset: dragonBones.DragonBonesAsset;
let atlasAsset: dragonBones.DragonBonesAtlasAsset;

Then, retrieve the 2 recordsdata and set them within the dragonborn’s armatureDisplay as follows

const bonesAsset = await this.assetBundle.loadFile(
        'BundleTEST',
        filePath + '_ske'
      );

      atlasAsset = await this.assetBundle.loadFile(
        '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 check, we run this course of with dragonbone materials for five characters in a bundle named BundleTEST.

Right here, each bonesAsset and atlasAsset are displayed accurately and a few characters are displayed, whereas others can’t be displayed as a result of atlasAsset is empty.

In case you test the log, you will note the next.

On the left on this screenshot is the conventional case,
DragonBonesAsset(ske) and DragonBonesAtlasAsset(tex), however in the best case
DragonBonesAsset(ske) is obtained, however DragonBonesAtlasAsset(tex) isn’t. Nonetheless, it doesn’t appear to be null or empty.

The code to learn a file from an asset bundle is as follows
There aren’t any errors logged on this code or any logs that point out that the studying fails.

  async loadFile(bundleName: string, fileName: string): Promise {
    strive {
      const bundle = await this.loadAssetBundle(bundleName);

      return await new Promise((resolve, reject) => {
        bundle.load(fileName, (err: Error | null, asset: T) => {
          if (err) {
            this.errorLog(`Did not load the file: ${fileName}`, err);
            reject(err);
            return;
          }
          console.log('SUCESS ' + fileName, bundle);
          resolve(asset);
        });
      });
    } catch (err) {
      this.errorLog(`Did not load the bundle: ${bundleName}`, err);
      return Promise.reject(`Did not load the bundle: ${bundleName}`);
    }
  }
  
  async loadAssetBundle(bundleName: string): Promise {
    return await new Promise((resolve, reject) => {
      assetManager.loadBundle(bundleName, (err: Error | null, bundle: AssetManager.Bundle) => {
        if (err) {
          this.errorLog(`Did not load the bundle: ${bundleName}`, err);
          reject(err);
          return;
        }
        this.bundleLog(`Success to load the bundle: ${bundleName}`, bundle);
        resolve(bundle);
      });
    });
  }

This challenge may be very tough.
If the file paths, and so forth. are flawed, I’d get an error similar to null, however that’s not the case, simply that sure recordsdata are empty, which may be very troubling.
I’m utilizing just one bundle, DragonBonesAsset and DragonBonesAtlasAsset, which have separate folders for every character, and there aren’t any recordsdata lacking.

Any options or tremendous strategies for this?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisement -spot_img

Latest Articles