Is there a performance difference between these two actions?

0 favourites
  • 4 posts
From the Asset Store
Alot of High Quality Items sound effects for your game!
  • Hi,

    I would like to know if there is a performance difference between using (create/destroy) and (set visible/set invisible)? Or doesn't matter wich method i choose to show/hide objects inside a layout?

    Sometimes set invisible is not adequate because even if the object is invisible it still interact with others objects, like collision and buttons sprites, which still clickable. In this case destroy appears to be more usefull.

    In some other cases destroy is not adequate and set invisible is the better option.

    So, i think it depends on the use you gonna give to objects, isn't it? But in relation to performance, how it works?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'd imagine it would be faster to change an object's visibility, rather than creating/destroying it.

    In both cases the object wouldn't be drawn, so rendering performance would be the same.

    If the object isn't destroyed it's still available for interaction though.

    Both have their uses, and it shouldn't be an issue of which is faster, instead just what makes sense in that situation. Usually I make invisible stuff that I'll either make visible again or just use for interaction. Whereas I destroy what is no longer needed.

  • If you are only managing small numbers of objects, this blog post applies:

    For large numbers of objects, creating and destroying objects is actually relatively CPU-intensive: the engine has a lot of internal data structures relating to created instances which all need to be updated when objects are created and destroyed. It's not slow per-instance, but adds up to a lot of work if you are handling hundreds of objects. In this case setting invisible (or repositioning far away) can be faster, but then you have to balance that with the fact they still exist and events will therefore still test against them. Repositioning far away is good with collision cells since it removes them as candidates for collision tests. Overall I'd say if you have a very large number of objects that are constantly appearing and disappearing very quickly, implement it by repositioning them far away instead of destroying. Otherwise normal create/destroy should be fine.

  • R0J0hound and Ashley,

    I'm honored! Thank you very much for this! I will use both, according to the situation. I don't have a lot of objets, but i was trying to optimize performance, so that was a concern...but not anymore. Thank you again for clarifying things for me!

    Best regards!

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