System protocol CPU performance qu… | Apple Developer Forums
System protocol CPU performance question Graphics & Games RealityKit You’re now watching this thread. If you’ve opted in to email or web notifications, you’ll be notified when there’s activity. Click again to stop watching or visit your profile to manage watched threads and notifications. You’ve stopped watching this thread and will no longer receive emails or web notifications when there’s activity. Click again to start watching. just_some_game_dev OP Created 3w Replies 1 Boosts 0 Views 81 Participants 2 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 to spawn the enemies using timer and budget a different one to move them to the player direction 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 Replies 1 Boosts 0 Views 81 Participants 2 Pokpong OP 3w 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. Add comment