Optimizing Actor Performance

by captaincomic (Updated on 2014-09-03)

One of the most important ways to ensure fast, smooth game performance is by making sure you're using actors in your game efficiently. The following tips can help you do this.



  • Avoid Excessive Actor Creation
  • Remove Actors when they're no longer needed


Avoid Creating Large Numbers of Actors Every Step

If you place a create actor block into the Always event block, like this...


...Stencyl will attempt to create an actor every single step, which would mean 100 actors per second. This will obviously slow your game to a crawl.



Instead, put blocks that create actors into the When Created, When This Collides, or When This Hears blocks, or constrain actor creation using a conditional (if statement).

In the examples above, we chose to create a recycled actor for bullets and explosions, the types of actors we would want to exist on screen temporarily and potentially have a lot of. F

or the menu button, we'll only have one, and it will be permanent, so we don't need to create a version we can recycle - we can use the regular Create Actor block.

If this all sounds trivial and completely obvious, you might be surprised to see just how often we see this happen in the field. ;)


Remove Actors When Possible

There are many times when you should remove an actor from your game. Examples include bullets, special effects, temporary power ups, enemies, and more.

Any actor the player's actor doesn't need to run into more than once is an actor you should remove. An actor you want to remove (when certain conditions in your game are met) will need a Behavior that provides the logic for removal.


There are two ways to remove an actor, using the kill [actor] block...

...or the recycle [actor] block. Make sure you don't attempt to recycle a regular actor and vice versa.


A few good ways to remove actors are after a set time period, using the Do After block...

The logic in this Behavior is designed to prevent errors from occurring where the engine attempts to recycle an actor that's already been removed.

Other options include when an actor collides with another or when it leaves the screen.

In this case, the boolean attribute called Actor On Screen? is there to ensure the actor isn't removed before it has a chance to appear on screen. You would use logic elsewhere to set that boolean attribute to true once that actor appears on screen. Then, when the actor leaves the screen again, the logic shown above will remove it from the scene.

One other tip for removing temporary actors is to use logic in a Behavior that removes an actor under a range of conditions, e.g. leaving the screen and after a short period of time.


Now it's your turn. Share your Tips.

What have you found, in your experiences, boosts performance of your games when you're in a bind? Use the comments area below to share your stories.

Disclaimer: All articles are geared towards Stencyl 3.0 and above. Use comments to provide feedback and point out issues with the article (typo, wrong info, etc.). If you're seeking help for your game, please ask a question on the forums. Thanks!


Is 'recycled actor' removed from stencyl 3.1? I can't find the block.
0 10 months, 2 weeks ago
What exactly happens when an actor is killed? In 3.0 it seems that the recycle actor option is gone, but after a while of killing and creating actors (basically the only functionality of my game) I experience very slow framerate.
0 1 year, 7 months ago
There's a typo (return pressed oddly) in your text:
___________________________________ __
In the examples above, we chose to create a recycled actor for bullets and explosions, the types of actors we would want to exist on screen temporarily and potentially have a lot of. F

or the menu button...
----------------------------------- ---------

Reconnect the two lines back into its proper paragraph.

1 1 year, 7 months ago
Dincicode: Excessive animation switching can impair performance because it allocates a new physics body. Looping doesn't make a difference either way.
0 1 year, 8 months ago
Does switching animations from 100 milliseconds to 200 milliseconds for actors improve performance, and what about looping animations does that make a difference if the actors only have 1 frame??
1 2 years, 6 months ago
I found a cause of lag also having many layers of trasparent backgrounds/foregrounds, to create an actor that collides upon another, bigger than screen and always simulating actors, creating more than 12 recycled actors at once(included point at and set velocity), to create trasparent actors.
0 3 years, 7 months ago
GC is not all that great, no matter what anyone says. I have also created XBLIG and the GC will often take more than a frame to complete causing a frame to drop. Do this often enough and you get a stuttering mess that since we do not have very deep debuggers would be difficult to find.

0 4 years, 1 month ago
One of the pictures has a create actor block in the "when drawing" wrapper.
2 4 years, 1 month ago
The recycle functionality is not completely bug free. That's why it isn't the default yet.

Creating new actors on the fly is expensive in Box2D. We found substantial, very substantial performance improvements using recycled vs. not.

1 4 years, 3 months ago
Yes I also wonder about the difference between recycled and non-recycled actors. If recycled actors improve performance, why not use them all the time? Why would you ever have to avoid it and use a regular actor instead?
0 4 years, 3 months ago

Sign In to Comment