Improbable Icon

SpatialOS Forums

Snapshots and player authority entities

Hi when we take snapshots before we update the server and a player is online while we take the snapshot we get errors when trying to reload those snapshots. This looks like it is because any items that the player is holding and has authority over are saved in the snapshot but once we try to reload the snapshot that player is no longer there (so their client worker entity is also missing) and we get errors that the snapshot can’t be loaded.

We currently just manually edit out those error items with a text editor but is there any way of doing this automatically when saving the snapshot? ie: if the authority of an item is a client then we should just save the authority as a worker so this doesn’t happen.

Hi @mythicalcity-JJ

Are you trying to remove those entities from the snapshots entirely? In that scenario you can use the persistence component to ensure that transient entities are not captured by snapshots.

If you want those held items to persist even without their owning player after the snapshot then things get a little more complicated. Can I ask for a little more context here on what behavior you’re trying to achieve in your project?

Hi @JHerd

In our game players can build. When they are building they are typically holding a construction item (like a wall) in their hand (this is in VR). They have paid resources to create that wall and it would be great if they did not lose it if the server goes down when they are holding it. The construction items are persistent as they make up the structures that players are building, so we can’t make them non-persistent. So there would be a few scenarios:

  1. At the simplest sense, if a held item simply transfers ownership back to the server (ie: this happens if a player drops an item) that would be good enough for now so that at least we don’t have to edit the snapshot.

  2. If we could force any held items to go back into the player’s inventory when the server is stopped so that the item is deleted and we update the player’s account (where we store the inventory) to restore the inventory item value. This way they wouldn’t loose or drop the item and the snapshot wouldn’t be saving that they are an owner as the item is deleted once it’s placed into their inventory.

Hi @mythicalcity-JJ

I see the problem you’re facing. We don’t currently have a tool to modify snapshots, though you could write a script to do that yourself if you can reliably filter the exact entities that need their authority changed.

In this scenario though I think the better solution would be to adjust your implementation slightly to avoid the problem altogether. As an example, if you waited until the player has actually placed the entity and conferred it to the managed worker’s authority before decrementing the inventory count there would be no risk of loss for the held item (assuming I’m understanding your current implementation correctly). At that point you could make the held objects non-persistent and simply disregard them in snapshots.

How feasible would something like that be?