Hello forum!
I'm running an ECS but still have problems with planning loading/saving.
Let's look at a specific case, a dragon-entity for example:
graphics_component =
{
texture_path = "..."
}
other_component =
{
...
}
So, this is an enemy, it will be used more than once, it is literally a class-concept that shall be instantiated during run-time. Therefore, it does not require a transform-component describing its location within the playable world just yet.
But what happens with the dragon-entity once it gets instantiated? Well, at some point, a transform-component will be added, that looks somewhat like this:
transform_component =
{
x = 100
y = 20
width = 64
height = 64
}
But wait, where do we get the width and height from? So let's just add a minimal version of the transform-component to our dragon-entity.
graphics_component =
{
texture_path = "..."
}
other_component =
{
...
}
transform_component =
{
width = 64
height = 64
}
Now, when we save our game, what are my possible strategies? Keeping track of all entity-files within a table and assigning instantiated entities to their fitting ID?
index =
{
[0] = "file/path/dragon.entity"
[1] = "file/path/rabbit.entity"
}
So a dragon-entity would obtain an id of 0.
And now, only writing the x- and y-coordinates into the save-file? Is this common? Assuming that the original level-file still contains a version of the transform-component that lacks information (x, y)?
My prior idea was to separate constant components (e.g. graphics) from variable components (e.g. transform). Keeping constant ones inside the blue-print and variable ones inside the save-file. This seems to be not doable without adding more components which would result in more complex code.
Is this it? Or are there better strategies?
Thanks for taking your time : )