Check if atlas contains an animation

Hello,

How can I check if an atlas contains an animation with a certain id?

Thanks!

We have no API function to do this.

Are you planning to add this?

No. The design philosophy of Defold is that knowledge of the scene graph and the structure of game assets is in the hands of the developer already from the content authoring stage. We do not wish to bloat the engine with a lot of functions to query scene graph or asset state when developers can track these things on their own.

Wouldn’t this be sort of a redundant feature since animations in atlases are created by the developer in the editor?

1 Like

My case is that I have an atlas with many characters’ faces. There are 3 different moods: happy, neutral, sad. But some of the characters can have only 2 moods (neutral and sad) and some can have only 1 mood (sad…in which case the ‘sad’ animation is already baked onto the character’s body animation. So these characters won’t have any animations at all in the faces atlas).

I have a single game object prefab where at init time I want to set that character’s animation based on its starting mood (which can be random). So I have just one big atlas where I have created animations with names “character_name_happy”, “character_name_sad”, “character_name_neutral”. And when setting up the characters I just want to use its id (mapped to the character_name) and mood (happy, neutral, sad). Then combine these two to get the final animation name, which is or isn’t in the atlas. If it isn’t, it should just use an empty animation. And it would be really easy to do this if there was that API. Now instead I have to keep an extra data set just to hold the information about the possible moods of the character. I would not have to do this if I could use an API and determine this at runtime.

Well, can’t you have all of them in the atlas, even for the characters with only one or two of the moods?

Example: In the case of the character with only a “sad” mode, let’s call him Frank, you could have frank_neutral and frank_happy both still reference the frank_sad image(s).

I can reference the same images? This should work yeah. Though it feels hacky.

Sure. If the image already exists in the atlas it will not be duplicated.

I think it sounds like a clever solution to a problem that would otherwise require you to write code :slight_smile:

3 Likes