Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

I prefer to code my own system, but can you give some insight into how yours works? I crashed my computer by spawning 1000 objects (but my computer is a bowl of egg salad anyway) 

(+3)

You're welcome to download it and check it out - it's all commented. Easier to answer specific questions when you've actually seen it ๐Ÿ˜‚

As for some tips on making your own system more performant:

  • Are you object pooling? If not, learn how to do that.
  • Do your bullets have rigidbodies? Remove them ๐Ÿ˜‰ rigidbodies are REALLY slow, and you can get away with just having rigidbodies on the colliders on your players/enemies.
  • If that's still too slow, you can actually get rid of the rigidbodies on the players/enemies and use Physics2D.OverlapCircle in FixedUpdate - I'd actually recommend the non-allocating version because you want to minimise your garbage collection.
  • Check your bullet spawning code for any unnecessary allocations - that's anywhere you've got "new". You can, for example, make a list a member variable and use list.Clear to clear it.
  • Check the profiler!! This is a big step, it'll show you where the majority of your performance issues are. You might, for example, be using Linq in your object pooling code to check if there are any available bullets. I was doing that, removing that linq code sped it up about 3x ๐Ÿ˜…

If that's still not enough, there are some major changes you can make to do it like I do:

  • You can rewrite it so all of the movement code is done from one object, and it just updates the positions of the gameobjects rather than the bullet gameobjects themselves having unnecessary monobehaviours attached
  • Once you've done that, it's fairly straightforward to use Jobs and multithreading to move the bullets
  • Once you've done that, you can try getting rid of Unity's physics entirely, and coding your own circle/circle collision detection as a Job
  • Finally, you can remove gameobjects entirely and use command buffers and a custom render pass. This is how I get to 20k bullets at 60fps ๐Ÿ˜‰

If 20k bullets at 60fps isn't enough, you can go full ECS. You probably don't have to do any of the last section, though, the first lot should be plenty to get 1000 on any hardware :)

Aren't you amazing I am an artist I try to code a lot but I just can't understand its logic properly. Can you give some tips on how I can improve as a dev. I did appreciate that man.

just practice! Practice, practice, practice ๐Ÿ˜‰ game jams are a good way of doing that.

Try things. Don't be afraid to just get stuck in: if something works, figure out why it worked. If something doesn't work, figure out why it didn't. 

All this comes over time. You'll get there!

(+1)

You might, for example, be using Linq in your object pooling code to check if there are any available bullets. I was doing that, removing that linq code sped it up about 3x

It is SUCH a shame that LINQ is so slow >_<

Especially if you then compare the performance of LINQ with what Rust offers and you see that in Rust using map/reduce is almost always as fast as a normal foreach loop and often faster than using a normal for loop to loop over your structure. And then there are even moments where it wins from both unless you try VERY hard.