Is it just a reference to a file or is there more to it than that? I'm planning on having thousands of packedscenes stored in arrays, not sure if that's going to eat up the resources or not.
How space-intensive is a PackedScene?
- Edited
Well it's going to take memory. Both on the disk (the file itself, which you will need either way) and also in RAM. When you call load or preload, it will load the file into RAM. RAM is cheap these days, you can assume most players have 8GB at least, so if the files are small, then you can possibly load a bunch (I have 64GB, for example, but I think most non-developers with new computers will have 16GB or 32GB max). The array storage is not much, since it is either only storing a string with the file path, or a pointer / reference, which is cheap. Still loading thousands may be a lot depending on what is inside. If the scenes / files are larger, you may need to find a way to lazy load (only load right before they are needed) and then release them from memory after they are gone, or you leave that area in the game. But it should be possible.
cybereality
Sorry if I didn't make my question clear, what I meant is thousands of packedscenes that point to the same .tscn file.
Basically, a big array containing many copies of the same packedscene. Pseudocode:
var theScene = preload("...theScene")
var someArray = [theScene, theScene, theScene, theScene, theScene, theScene ...]
From the sound of it the array is just going to be an array full of some equivalent of strings? which sounds fine by me
- Best Answerset by GE100
Yes, they would be storing references, which are essentially pointers. I'm not sure how it's implemented in the Godot source code, but I imagine it would be 64-bit pointers, meaning each one would take 8 bytes of memory. Very small. However, if you have an array with thousands of the same value, it probably means there is some problem with your design. For example, you can use a Dictionary to store sparse data, it doesn't make sense to have an Array that large.
- Edited
GE100 If I understand the question right, I actually asked a very similar question beforehand. The answer is that Godot is very optimized, and works in a smart way that if you instance the same scene several times, or even assign it to several variables (aka. load it several times), the RAM space taken is ONLY that of ONE scene (EDIT: maybe technically slightly more than that, but not visually noticeable as far as Godot's debugger is concerned). You can see a project that I made myself to test this here https://godotforums.org/d/30623-does-instancing-the-same-object-several-times-increase-ram-usage/11.
However, beware, because using things against the way Godot intended could cause this smart behavior of Godot to load scenes once to... malfunction. An example is I had an autoload which had the current scene loaded (and during the loading screen a different scene is loaded as the current one). This should work wonderfully, with Godot loading the scene once, except that this "autoload" was not really one, but rather a node that was added manually mid-run (and not part of the main scene). Because of how autoloads are structured, Godot probably didn't recognize the supposedly "autoload" node, and basically loaded my main scene twice. You can read more about the technicalities of this issue here https://godotforums.org/d/30633-autoload-cannot-be-added-in-runtime/13.
Bottom line is, if you try to "innovate" and change the way Godot is supposed to be structured or the way Godot is supposed to work, be careful, as such smart features might not work.