System protocol CPU performance question

Hello guys

In my game the player sits in the middle of the screen and shoots on enemies coming all around it. (none vr/ar game)

I have 3 :systems protocol already

  1. to spawn the enemies using timer and budget
  2. a different one to move them to the player direction
  3. pool system that turned off dead enemies

Because reality kit is a high level framework i dont know what is the fastest way to design the bullet system for better cpu speed

A. Seperated system for the bullets, asking to know the closest enemy to travel to, hit, and move to the disable pool system if died.

or

B. Use the same system that moving the enemies but in a seperated loop (prabably one before moving the enemies)

Thanks for the help

I wouldn't expect A versus B to be faster just because the bullet loop is in a separate System. The important part is how much work each update does. RealityKit Systems are designed to update a query of matching entities together; Apple recommends using an EntityQuery and avoiding unnecessary work in update(context:).

For bullets, try not to find the closest enemy by checking every bullet against every enemy on every frame. If a shot is aimed, choose its target when firing and store that target on the bullet. If bullets should hit whatever they reach, give them simple collision shapes and use collision events, with collision groups so bullets only test against enemies. Keep pooling, and remove expired bullets from active queries. If you really need nearest-target seeking, retarget occasionally or use a spatial grid instead of a full scan.

I'd start with a BulletSystem that queries active bullets and moves them using the frame delta time, then profile with realistic enemy and bullet counts in Instruments. If the bullet count is small, the simpler implementation may already be fast enough.

Apple's guides on RealityKit Systems and collision detection are useful starting points.