How do I efficiently determine which of 100+ weapons to fire?

0 favourites
  • 6 posts
From the Asset Store
100 high-quality cars / boats. This asset is perfect for a top-down game.
  • I've run into a problem where when the player presses the fire button, the game has to check the names of over 100 weapons at this point such as in the screenshot. It only happens in a function that triggers when the character is told to fire a weapon, so it only happens for one tick normally when playing. The problem comes where if I remove all limitations from the character and rapidly press the fire button, it can get really bad with CPU usage due to that function call. So I was wondering if there is some other way I can do this that isn't so inefficient.

    This is not a weapons system such as in an RPG where you just get stat boosts and a special attribute sometimes. These are different kinds of projectiles and such that all behave very differently.

  • Oh wow I forgot those even existed because I never had thought of a use for them. I guess now you pointed me in the right direction and I'll try it.

  • Use function maps

    https://www.construct.net/en/make-games/manuals/construct-3/project-primitives/events/functions

    I tried it moving each weapon to its own function. Spamming the fire button with no limits still causes the CPU to go up a fair amount, but it's definitely well within the acceptable range unlike before and I can probably just fine tune the weapons to reduce how much they use CPU.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Glad it worked

    If there are lots of projectiles I can imagine there's probably some low hanging performance-improvement fruit to pick

  • Glad it worked

    If there are lots of projectiles I can imagine there's probably some low hanging performance-improvement fruit to pick

    Yeah thanks for the help. I can debug the weapons for their performance impact by just disabling the limit of shots on screen and spamming the fire button as fast as I can which is what made me notice this. lol

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)