Such a thing as too many variables?

Godot Version

4.5

Question

So I am working on a JRPG with a LOT of story variables, majority of them booleans. To make saving and loading simple, I have the data resource full of those variables which are accessible via an autoload Data node. (The data resource just sits on the node, and isn’t saved to an actual file until you’re saving, and at that point it’s a duplication of the current data rather than assigning it.)

Do we know for sure if there is a performance hit if I have a ton of variables? If there is I’m willing to move it all to a Dictionary[String, bool] inside that data resource, but I really really like being able to use the autocomplete/intellisense when accessing story variables.

The data file’s code is below. Take notice underneath where it says Story Flags, later on there will be a TON of variables there for story progression.

class_name DataFile
extends Resource

#Routine Information
@export var current_map:String
@export var player_location:Vector2

@export var items:Array[int]
@export var item_quantities:Array[int]
@export var weapons:Array[int]
@export var weapon_quantities:Array[int]
@export var armors:Array[int]
@export var armor_quantities:Array[int]

@export var actors:Array[PackedScene]
@export var party:Array[int]
@export var actor_info:Array[Dictionary]

@export var quests:Array[Quest]

@export var bgm_track_path:String
@export var bgm_volume:float
@export var sfx_volume:float
#Story Flags
@export var first_cutscene:bool
@export var first_battle:bool
@export var first_armor_cutscene:bool
@export var first_outside_cutscene: bool
@export var switches:Dictionary[String,bool] = { #This was me testing if there is intellisense when using a typed dictionary... there is not :( 
	"first_outside_cutscene" : false
}

There isn’t.

What order of magnitude is a ton? 100?

1 Like

A few hundred at most? Hard to estimate but it’ll be over a hundred at least

Design-wise there’s probably a better way to structure your data but technically this shouldn’t affect performance in any way.

3 Likes

Do you have any suggestions or resources I can reference for this? I know I can use arrays and dictionaries for a lot of data but not sure if there’s anything better

enums are popular

It’s not a matter of “something better”. If your data is laid out flat then it’s completely irrelevant whether you store it in a bunch of variables or a dictionary.

The real question is does your data need structuring. Do some parts of the data need to reference other parts? This is a design question. If the answer is yes, then you need to write this structure down or draw a diagram. Once you have this, you can start thinking of ways to best reflect that structure in your implementation.

There are really only 3 types of basic data containers: objects, dictionaries and arrays. The key is in figuring out how to combine them to best reflect your structure.

3 Likes

I mean, if you want a ultra performant project, having some hundred boolean and arrays shouldn’t affect it that easy.
It would make things start to get a bit heavier in memory if you set too many @onready vars instantiating really large scenes.
I’m pretty new to Godot too, but you shouldn’t care too much about it since the engine gives you all the tools to improve game performance.