All Questions

Community

o
Omar omar.bazzi.sf

export var scene --> String vs PackedScene

Hi! Would you tell (if any) the cons of using PackedScene (like in the portal scene)? 'cause I like that way better than "string" (I really don't like to give that freedom to put any string, always thinking on a team work). Thanks
  • Nathan Lovato replied

    The biggest issue is loading cycles. Say you have scenes, A and B.

    They both take a PackedScene as an exported variable. A references B, and B references A. When you load B from A, Godot will read the scene and see that there is a packed scene as a dependency. That scene is A, so it loads it. It sees B in there, and loads it. And it does so in an infinite cycle, freezing your game.

    So you have to be extra careful to not cross-reference scenes.

    Working on a larger game, with a team, I would rather use strings, but maybe also a custom-made addon that lets you pick and display the level your portal leads to.

  • o
    Omar omar.bazzi.sf replied

    Great. I thought that cycle reference was a problem even with strings.

  • Nathan Lovato replied

    No, cycle references only happen when Godot finds a pointer to a file, then it has to load it to get some information from it. For Godot, a string is just a string. You can also have circular references with GDScript, when two scripts reference one another as types because Godot loads and parses the other for autocompletion.