#Pause and play particle system with dots

1 messages · Page 1 of 1 (latest)

livid burrow
#

can anybody help me i am working with unity dots and cant figure out why the particle system is not pausing

using Unity.Entities;
using UnityEngine;

namespace _Scripts.Systems{
    public partial struct EnemySpawnVFXSystem : ISystem{
        
        public void OnCreate(ref SystemState state){
            state.RequireForUpdate<EndSimulationEntityCommandBufferSystem.Singleton>();
        }
        
        public void OnUpdate(ref SystemState state){
            if (!SystemAPI.TryGetSingletonRW(out RefRW<GameManager> gameManager)) return;
            var isPause = gameManager.ValueRO.pause;
            var em = state.EntityManager;
            
            foreach (var (tag, entity) in
                     SystemAPI.Query<RefRW<ParticleTag>>()
                         .WithEntityAccess())
            {
                var ps = em.GetComponentObject<ParticleSystem>(entity);

                if (tag.ValueRO.IsPaused != isPause)
                {
                    if (isPause)
                        ps.Pause(true);
                    else
                        ps.Play(true);

                    tag.ValueRW.IsPaused = isPause;
                }
            }
        }

        
        public void OnDestroy(ref SystemState state){
        }
    }
} ```