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?


Yes, perhaps the inventory change after release would be good. I guess we would also have to destroy the entity if the player was destroyed or disconnected while they were holding it so that it didn’t drop down and become usable by another player.

Are we able to change the persistence of an entity? ie: make it non-persistent when held and then persistent once released? and if so, how would we do that in Unity (SDK)?

Thank you!

Hi @mythicalcity-JJ

Unfortunately we don’t currently offer a way to change an entity’s persistence dynamically in the Unity GDK or deprecated SDK.

Ok. In that case how would we have the construction item be non-persistent if it’s meant to be persistent?

Hi @mythicalcity-JJ

I imagine you might want to use two entities, one for each state, and create/destroy them as necessary between the item being held or placed.

Ok. That doesn’t sound to efficient though, it will require us to make special versions of each of our construction objects and to do that from now on. It would add a lot of error prone duplication workflow.

What do other games on Spatial typically do for player authority objects when they do snapshots?

It seems odd that the snapshot would save things that it can’t load. Wouldn’t it be simpler for the snapshot loading process to just assign the ownership to a worker if it can’t find the client owner online when it’s loaded?

There are other alternative implementations that you might want to consider, such as not making these objects player authoritative in the first place (and this would probably be a better approach overall).

When it comes to snapshots they aren’t designed to capture entities that have player authority. Such entities aren’t meant to be persistent. If you want to allow a player to move an object in the environment you can do that without changing its authority from whichever worker currently owns it.

I see, that could work functionally but my concern is that in VR you hold the construction item in your hand and you want to be able to place it exactly. So a server network delay (even if it’s very short) could be frustrating to players. That’s why we give authority to the player over these objects so that the object movement is exact 1:1 to their hand movement.

If I understand your suggestion correctly that is :slight_smile:

Hi @mythicalcity-JJ

Yeah, that solution would indeed introduce a small network delay and I totally understand the concerns there. VR is definitely a different beast to normal games and will need some different approaches to problems like this. I do think your best solution is going to be simply avoiding the persistent object having player authority though.

Another suggestion: Have you considered having the player hold a dummy object that has no SpatialOS entity at all (or is at least excluded from snapshots), and then having the actual worker entity follow it in some way? That way the player will have perfect 1:1 tracking visually, even if the worker entity has that slight network delay.

I recognize that this may entail some changes on your part in terms of creating a separate object for manipulation.

Yes, that would work but then other players couldn’t see what you are building. In the game people are often building together and it’s nice to see that you are about to place something in a specific spot. Also, when you let go of the item it has the ability to snap into a specific position/rotation and sometimes players want to move it after they snapped it to just tweak the position a little bit. This would mean everytime they selected the object again we would be destroying the entity and instantiating the local object that they are holding.

Other players would still be able to see the persistent entity moving. In fact they’d be seeing it with more or less the same latency as they would using your current implementation, as the entity would be receiving the same position updates. The updates would just be coming indirectly from the proxy object held by the player instead. You could then mask this for the player actually holding the object by toggling visibility on the ‘real’ persistent object so they only see their local proxy.

I’m sure you could design this in a way that wouldn’t require repeated creation or destruction of game objects or entities as well.

Ok I think I understand what you mean now by the proxy object. Thanks, we’ll take a look at how we could implement that. I’ll let you know if we get it working.