#How do you play the full particle system in ECS and not just the parent effect?

1 messages · Page 1 of 1 (latest)

native kindle
native kindle
#

I think understand why it is made this way since everything with ecs is on a "per entity" basis...
I came up with this recursive playback extension method...but I'm hoping there's something better...

public static class ECSParticleSystemExtension
{
    public static void Play(this ParticleSystem root, Entity rootEntity, ref SystemState state)
    {
        root.Play();

        if (!state.EntityManager.HasBuffer<Child>(rootEntity))
            return;

        DynamicBuffer<Child> children = state.EntityManager.GetBuffer<Child>(rootEntity);

        for (int i = 0; i < children.Length; i++)
        {
            Entity childEntity = children[i].Value;
            if (!state.EntityManager.HasComponent<ParticleSystem>(childEntity))
                continue;
            ParticleSystem childFx = state.EntityManager.GetComponentObject<ParticleSystem>(childEntity);
            childFx.Play(childEntity, ref state);
        }
    }
}
hollow frigate
#

I'm sure this is what would be happening under the hood if you weren't doing it yourself 😄

hollow frigate
#

something has to make those particle effects play, you just do it yourself here

#

I don't think there's a problem with your code basically
you could of course create a component to cache the particle system hierarchy, but I don't think that's worth it (especially if your hierarchy is only particle systems)