#Linking `ScriptableObjects` with animations and accessing it within a system

1 messages · Page 1 of 1 (latest)

lime ginkgo
#

I have a few ScriptableObjects in my Assets folder that are kind of extensions to existing AnimationClips (because I couldn't find a better way to add this data to the actual clips). they look like this:

[Serializable]
[CreateAssetMenu(menuName = "Everterra/Animation Hitboxes")]
public class AnimationHitboxes : ScriptableObject
{
    public List<AnimationHitbox> Hitboxes = new();
    public float StopAtNormalizedTime;
    public AnimationClip Animation; // This is the "link" with the animation clip
}

now in an ECS system I want to be able to pick the respective ScriptableObject for the current animation that the character is playing, what would be a good way to do this?

I thought about doing a bit of codegen, similar to what the new Input System does. I would generate a static class with a map of AnimationHash -> ScriptableObject, maybe something like this:

public static class AnimationHitboxMap {
    private static AnimationHitboxes _anim1 = new AnimationHitboxes() { ... }

    public static AnimationHitboxes ByHash(uint hash) {
        switch (hash) {
            case 111: return _anim1;
            case ...: return ...;
        }
    }
}

but it looks kinda weird and I am not sure I can read this static class from within a system?

I thought about another solution that looks "more ECS", but I am not sure how it would actually look like in practice:

  1. use a baking system (is this a valid use case for them?) to find all these ScriptableObjects
  2. create a singleton entity that holds a BlobAssetReference for a big array containing all hitbox data, and a NativeHashMap to allow me to get the hitbox data for a specific aniamtion without iterating through all items
  3. access this singleton in the system that I need the hitbox data

is it correct to use a baking system to create this singleton? athinq

#

Linking ScriptableObjects with animations and accessing it within a system

#

I am also open to any other suggestions to solve the actual issue of adding additional data for the AnimationClips

silver crag
#

You can`t access scriptable objects but you can bake another representation of it

silver crag
lime ginkgo
#

now that I am thinking more about it, I might not even need a singleton and blobassets for all hitboxes in the game, I could read the animation from the game object itself and attach the hitboxes data as a normal component

#

ah but I still need to find the scriptable object from the baker, without a global cache I will hit the disk a lot of times to find the file for each entity

lime ginkgo
silver crag
#

ScriptableObject

#

Then on blob assets