Why is there a load() at all?

  • Gamma@beehaw.org
    link
    fedilink
    English
    arrow-up
    5
    ·
    1 year ago

    In GDScript, there exists the global preload method. It loads resources as early as possible to front-load the “loading” operations and avoid loading resources while in the middle of performance-sensitive code.

    Its counterpart, the load method, loads a resource only when it reaches the load statement. That is, it will load a resource in-place which can cause slowdowns when it occurs in the middle of sensitive processes. The load() function is also an alias for ResourceLoader.load(path) which is accessible to all scripting languages.

    From the docs: https://docs.godotengine.org/en/stable/tutorials/best_practices/logic_preferences.html

  • I Cast Fist@programming.dev
    link
    fedilink
    arrow-up
    5
    ·
    1 year ago

    For a personal project, I’m using load() because I don’t know which file I’m supposed to load when the scene starts. Also, said file can change during game runtime.

    In my case, I’m changing textures. With the game paused, the player can change some stuff, like the character’s hair. I don’t need to preload all of them, and maybe a preloaded one might not be the one that should actually be loaded in the end.