#Entity spawning on input resulting in Assertion Fault

1 messages · Page 1 of 1 (latest)

left whale
ruby oar
#

turn off burst so you can see your error better

#

(also you shouldn't be using Entities.ForEach, or use ECBS like that anymore. This code is very dated)

#

oh your error is you're doing this in a FixedUpdate

#

but using a non-fixed update ECBS

#

so if your fixed update runs twice before your playback happens

#

you're going to create 2x the fireballs and try to remove CastSpellRequest twice

#

and removing it a second time is what causes your error

left whale
#

i see, i thought that might have been the cause but didnt know why

#

whats the entities.foreach replacement recommendation?

just standard foreach query right?

RefRO<LocalTransform> localTransform,
RefRO<PlayerComponents.PlayerTag> playerTag,
RefRW<PlayerPosition> playerPosition)
in SystemAPI.Query<
RefRO<LocalTransform>,
RefRO<PlayerComponents.PlayerTag>, 
RefRW<PlayerPosition>>())```

like this?
ruby oar
#

yes

#

well in your case no

#

because you're doing a job

#

should be IJobEntity

#

IJobEntity replaces Entities.ForEach
SystemAPI.Query replaces Job.With

left whale
#

so something kind of like this?



    [BurstCompile]
    public partial struct ChaseEnemySpawnerJob : IJobEntity
    {
        

        public EntityCommandBuffer.ParallelWriter commandBuffer;
        public Entity enemyPrefab;
        
        
        public void Execute([EntityIndexInQuery] int entityIndex, in LocalTransform localTransform, ref EnemySpawner enemySpawner)
        {
            Entity enemyEntity = commandBuffer.Instantiate(entityIndex, enemyPrefab);
            commandBuffer.AddComponent(entityIndex, enemyEntity, new EnemyMover
            {
                moveSpeed = 3f,
                rotationSpeed = 10f
            });
            commandBuffer.SetComponent(entityIndex, enemyEntity, LocalTransform.FromPosition(localTransform.Position));
        }
    }

this is what i do to spawn enemies with a job

ruby oar
#

yes

left whale
#

alright ill give this a shot thank you

ruby oar
#

but yeah, underlying problem is just using wrong entity command buffer system

left whale
ruby oar
#

yous till have a similar issue here as you're updating in FixedStepSimulationSystemGroup

#

BeginSimulationEntityCommandBufferSystem.Singleton
this should be EndFixedStepSimulationEntityCommandBufferSystem