-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Given a State, which is possible to create at the moment, which manages its data with a prefab, there currently is no way to clean up prefab-bound entities if the data was loaded from a save.
export class GameState extends State {
_systems = [...];
prefabHandle?: TPrefabHandle;
create(actions: ITransitionActions) {
if (actions.getResource(MenuSelection).continueLastGame) {
// no way to fill the prefab handle here!
loadGameFromSave(actions);
} else {
this.prefabHandle = createNewGameFromPrefab(actions);
}
actions.maintain();
}
destroy(actions: ITransitionActions) {
// target: remove the `if`, we should always clean up!
if (this.prefabHandle) {
actions.unloadPrefab(this.prefabHandle);
}
}
}One idea might be to pass a unique ID to the loadPrefab() method, so it can mark entities and find them when loading a save, but that sounds complex for users. Maybe the ID could be a hash (of the prefab) and a new method (const prefabHandle = world.linkPrefab(prefabObj)) could be used to retrieve the handle, however that sounds bad when it comes to using updated prefabs on an old save. Then there also must be a method to upgrade the prefab handle to the new prefab version.
A completely different way to handle this might be to make it explicit which data is saved, always require a prefab to be loaded, and have saved data overwrite the prefab data. This means a lot more syncing, though, since then a prefab needs to include the necessary information to do such a sync, or the ecs needs an algorithm which can bind the data, which, just like before, sounds like a problem when changing the prefab slightly for a version update.
One more way would be to chunk the data in the save to make extraction possible per chunk, where a chunk could be tied to a state, or anything a user may want, really.
I won't stall v0.3.0 for a fix for this problem, though, since progress is slow as is.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status