Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prefab handle + save file = undefined #29

Open
minecrawler opened this issue Dec 9, 2020 · 1 comment
Open

prefab handle + save file = undefined #29

minecrawler opened this issue Dec 9, 2020 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@minecrawler
Copy link
Collaborator

minecrawler commented Dec 9, 2020

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.

@minecrawler minecrawler added the enhancement New feature or request label Dec 9, 2020
@minecrawler minecrawler added this to the 1.0 milestone Dec 9, 2020
@minecrawler
Copy link
Collaborator Author

Tags landed in v0.3.0, which makes it easy to tag entities with the prefab handle. The logic should work like this:

  1. When loading a prefab, generate a UUID as handle (instead of a number). Tag all new entities with the handle and use a way for the tag which makes it distinguishable as a prefab handle
  2. When loading a save or prefab, fill the prefab-cache (world.entityLinks), too
  3. Unloading will work out of the box

For now, storing and loading the actual handle is left to the user. I am open to ideas to make it simpler

@minecrawler minecrawler added the good first issue Good for newcomers label May 11, 2021
@minecrawler minecrawler added help wanted Extra attention is needed and removed good first issue Good for newcomers labels Sep 30, 2021
@minecrawler minecrawler moved this to High priority in Fix Bugs Jul 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Status: High priority
Development

No branches or pull requests

1 participant