Command to "Reload sprites when on screen", which was destroyed by "Behavior" "Destroy when off screen"

Command to “Reload sprites when on screen”, which was destroyed by “Behavior” “Destroy when off screen”

The objects have been destroyed, they don’t exist anymore, so they can’t be “on screen”.

The problem i have with "destroy when off screen is.
For example: If I have a big level, when go further the objects in the level were already destroyed, because they were already off screen.

So there should be a way to make it works both ways destroy and reappear.
If this can be possible it will improve performance a lot, allowing to create as much big levels as you want.

You should read this article
http://wiki.compilgames.net/doku.php/gdevelop5/events/draft-optimization

Thanks there were some useful optimization tips, but what im saying here is a action for reloading the destroyed objects, when on screen.
Which is not included in Gdevelop yet.

you obviously cant do that.
if you do not want to delete your objects, use hide object.

Hiding will work if there are different objects on different parts of a level.

But hiding will not work if I have same objects reused in the whole level.

For example: An object which is reused in the whole level and I want that object to only appear on screen and disappear off screen.

If there is a way to do this then tell

hide all and use distance check to show/hide them.
i am uncertain if gdevelop does this on its own (i would assume it does).

I think yr right its already in Gdevelop, it automatically hides items off screen.

http://wiki.compilgames.net/doku.php/gdevelop5/events/draft-optimization

Check here in “Optimization already in the engine” tab

But it also says: It is still important to hide or disable what you don’t need. This is the key to optimization.

But it would improve performance lot more if objects are destroyed and rebuilt on screen

no it would not increase the performance.
it needs to know all the same things it needs to know if its hidden.

where and what are variables it needs to store and check to draw objects.
same would be true for your requested function restore on screen.
no performance gain.

1 Like

Maybe yr right, I will do some testing to check if

  1. It really does hide automatically or will performance be better if I hide objects myself.
  2. Will destroying have better performance than hiding.

to accurately compare that you have to:
store the position and object for each off-screen object in variables.

my guess would be that those position tables are internally checked in c++ tables and are much faster then manually checking variables with js.

1 Like

Performance wise, that wouldn’t make much sense. The point of destroying an object is to free the memory. For example, let’s say an object take 1 kb of memory (just an example, it is extremely unlikely to be the case). If you no longer need it, you can delete the object (destroy it), to have one more Kilobyte of free ram. An object take performance for two reasons: holding data (takes memory) and rendering (takes CPU and GPU performance). What you want to do, is using much cpu power and memory to copy the data of the object, delete the object, including extra operations for object deletion like unlinking all linked objects, and do all that backwards again later (which takes more performance as you need to recreate an object Instance that because of js internals may cause some additional overhead). All of that for what? Sure, there is no rendering, but by hiding the object you can also prevent rendering. Memory wise, you still have all the object data in memory.

The only potential thing it could help with is the event sheet, as technically it makes less objects to test collisions with. Though, the gained performance will not be worth it compared to the costs, and just optimizing your events might help much more.

In my case i have most objects with collision system, will hiding them increase performance?

The best for performance would be to use a condition to only select object on screen.
Hiding will always make performance better, though you don’t need to worry about that, GDevelop has built-in culling, meaning offscreen objects are already forcefully hidden without needing you to do anything.