sinbad / SPUD

Steve's Persistent Unreal Data library
MIT License
300 stars 44 forks source link

Ability to return to previously saved level #66

Open krojew opened 5 months ago

krojew commented 5 months ago

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.

sinbad commented 5 months ago

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.

krojew commented 5 months ago

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?
sinbad commented 5 months ago

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)

cyphusx commented 5 months ago

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

krojew commented 5 months ago

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

cyphusx commented 5 months ago

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.