Engine API Reference
    Preparing search index...

    Class AssetReference

    An object that manages the case where an object holds a reference to an asset and needs to be notified when changes occur in the asset. e.g. notifications include load, add and remove events.

    Index

    Constructors

    Accessors

    Constructors

    • Create a new AssetReference instance.

      Parameters

      • propertyName: string

        The name of the property that the asset is stored under, passed into callbacks to enable updating.

      • parent: any

        The parent object that contains the asset reference, passed into callbacks to enable updating. Currently an asset, but could be component or other.

      • registry: AssetRegistry

        The asset registry that stores all assets.

      • callbacks: { add?: any; load?: any; remove?: any; unload?: any }

        A set of functions called when the asset state changes: load, add, remove.

        • Optionaladd?: any

          The function called when the asset is added to the registry add(propertyName, parent, asset).

        • Optionalload?: any

          The function called when the asset loads load(propertyName, parent, asset).

        • Optionalremove?: any

          The function called when the asset is remove from the registry remove(propertyName, parent, asset).

        • Optionalunload?: any

          The function called when the asset is unloaded unload(propertyName, parent, asset).

      • Optionalscope: any

        The scope to call the callbacks in.

      Returns AssetReference

      const reference = new pc.AssetReference('textureAsset', this, this.app.assets, {
      load: this.onTextureAssetLoad,
      add: this.onTextureAssetAdd,
      remove: this.onTextureAssetRemove
      }, this);
      reference.id = this.textureAsset.id;

    Accessors

    • get id(): number

      Gets the asset id which this references.

      Returns number

    • set id(value: number): void

      Sets the asset id which this references. One of either id or url must be set to initialize an asset reference.

      Parameters

      • value: number

      Returns void

    • get url(): null | string

      Gets the asset url which this references.

      Returns null | string

    • set url(value: null | string): void

      Sets the asset url which this references. One of either id or url must be called to initialize an asset reference.

      Parameters

      • value: null | string

      Returns void