Handling projectile collisions

I’m making a 2D shooter using scriptable objects and actual projectiles instead of raycasts and I’ve run into a problem. I know having projectiles is heavier when it comes to performance by default, however, I’m concerned that having each projectile handle collisions by themselves in a script will eat up performance even more than the physics itself. Is this something I should worry about? Is there a better way to do this I haven’t thought of?

A common mistake is to optimize before you’ve started. Have you tried a simple prototype? Instantiating multiple gameobjects and collision-checking for each should be fine, but it depends on multiple factors such as how many bullets will exist at once in the game. 10s? 100s? 1000s? If you’re going to have a lot of bullets you could try object pooling, where you simply hide inactive bullets and reset and reposition them when you fire one.

If optimization really is an issue you can do a combination of raycast and collision checking. For instance, raycast forward on a “Solid” layer mask to check where the bullet would hit. Then every frame move the bullet and check for Physics.OverlapSphere with a radius of zero on a “Enemy” layer, to check if the bullet has hit anything. Once it reaches the pre-calculated “Solid” hit, destroy the bullet.