Element.sprite only returns null

Hey, I’m trying to access a sprite asset I added to an entity with an element component.

this.entity.element.spriteAsset → works, but returns the prite asset ID, so instead I wanna use:

this.entity.element.sprite → which according to the API should retun a reference to the sprite asset itself (see API), but I only get: null.

Any ideas what it could be? Engine bug?

1 Like

Hi @Astra,

I think that’s how it worked for a long time, the spriteAsset is consumed directly without populating the sprite property. Same with texture/material, not sure why it’s like that though.

To get the asset use the ID in the assets registry:

const spriteAsset = this.app.assets.get(this.entity.element.spriteAsset);
2 Likes

Neat. Thx!