Calling a function every tick VS running actions with normal conditions

0 favourites
  • 9 posts
From the Asset Store
Full game Construct 2 and Construct 3 to post on Google Play
  • Hi,

    Is there any difference between having a subconditon action being run every tick and every tick calling a function that runs the same action?

    I'm asking because for some reason the FPS seemed to drop after I changed almost all of my actions to run as functions.

  • functions are slower since you basically run a function to run a function and it adds overhead

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Should Functions then be always used to complete actions that take one tick to finish?

  • Use functions when you want to do something regular actions can't do because of conditions and picking, or to simplify your code because simple code is sometimes more important than performance, or to run code inside an action, there'S like a million uses for functions !!

  • it could be that your functions are doing more than you think they are.

    functions do not know what instances were picked when the function was called, and will therefore apply to all instances, unless you re-pick instances inside the function - which can add a lot of overhead if you have a lot of instances and/or are picking based on time consuming factors.

    if you are passing in a UID of an instance, and just running actions on that one instance, then I would not expect any difference in performance by using a function.

  • Hi,

    Yeah I have an UID parameter in all functions that identify which instance is picked. The function is run for each instance that meets the original conditions to trigger the function.

  • It probably doesn't matter, and worrying about it will only distract you from other more important things that actually matter.

  • Hi,

    Yeah I have an UID parameter in all functions that identify which instance is picked. The function is run for each instance that meets the original conditions to trigger the function.

    Functions won't really slow you down, but For Each will! You have to be careful when using it. One tip I have is to make sure you do all the picking BEFORE the For Each

    For examnple:

    you have 10 sprites. 5 are blue and 5 are red

    Sprite = Blue

    For Each Sprite

    This will run 5 times. First it picks all the sprites that are blue, and then it goes over each one

    For Each Sprite

    Sprite = Blue

    This will run 10 times. It will go through each Sprite one by one, checking if it's blue

    So you want to do your picking before your For Eaches when possible. This will weed out only the objects you need to do For Each on, which will help performance

  • Hi,

    Yeah always have the loop conditions very last in the condition.

    Anyhow, it's good to know that functions that run every tick shouldn't cause slowdown any more than normal conditions that run every tick.

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