SPUD icon indicating copy to clipboard operation
SPUD copied to clipboard

Ability to return to previously saved level

Open krojew opened this issue 1 year ago • 6 comments

Currently the plugin is meant to save and restore the state of current level. It would be nice to give the possibility to save level state to an object, which can then be restored if the given level is returned to. Example usage: player drops an item in a level, goes to another one, and returns to the previous level. The dropped item should till be there.

krojew avatar Jan 26 '24 16:01 krojew

This is already supported automatically through the level unload / load hooks - that's how sublevel streaming works. You do however need to make sure that you spawn your objects in the correct level so it's associated with that level when the level unloads.

sinbad avatar Jan 26 '24 19:01 sinbad

Would this work in given situation:

  1. Level with World Partition is loaded for the first time.
  2. An actor there travels from its original cell to another one.
  3. Another level is loaded.
  4. The first level is loaded again. Given the actor gets spawned in a different cell than it was in while exiting the level, will its state be properly restored?

krojew avatar Jan 26 '24 20:01 krojew

The cell travelling is probably an issue. I didn't actually implement the world partition support (I don't use it) but with e.g. streaming sublevels you have to change the owning level of your actors if they move between levels. I'm not sure how actor/level ownership works with WP cells offhand (I'm not at my PC to check, perhaps have a dig around yourself)

sinbad avatar Jan 27 '24 15:01 sinbad

WP works much the same way - you'd have to change ownership as the actor moves into the new level. There's the slight wrinkle that if the actor overlaps the cell boundary you technically should add it to the cell one level higher in the hierarchy (and keep going until you're not overlapping), but you may not be too bothered about things appearing that overlap the edge when the cell level is loaded

cyphusx avatar Jan 28 '24 07:01 cyphusx

@cyphusx would you have any details on what events to listen too if actor moves into a new cell?

krojew avatar Jan 28 '24 07:01 krojew

Unfortunately there aren't any that I'm aware of.

You could possibly listen for the level unload events, get the corresponding cell bounds and change ownership then, but I'm not sure if that event fires early enough for you to do that. In addition to finding any actors within those bounds that don't belong to the level being unloaded, you'd also need to identify any actors that are owned by that level but which have moved out of the bounds and change their ownership to another level.

You could alternatively just update the ownership whenever the actors move, but that may be too costly depending on how much they're moving.

cyphusx avatar Jan 28 '24 08:01 cyphusx