sinbad / SPUD

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

WorldSubsystem property saving issue #65

Open YeNov opened 8 months ago

YeNov commented 8 months ago

Hello, I have an issue with world susbystem field is not getting properly restored. Setup is quite simple:

I tried different approaches - custom spawn, adding SpudGuid, but that didn't help. CustomSaveData doesn't help as well, because custom restore happens before object is destroyed. Any ideas what can I do? Is it maybe possible getting specific save state and read from it manually after instance is recreated? Is it worth looking into how properties are managed between world subsystem re-construction? Or is it something that should be supported and my setup is just slightly wrong?

Thanks

sinbad commented 8 months ago

Technically a world subsystem isn't a global object - it's scoped to the UWorld, which gets destroyed and re-created whenever the UWorld does, which makes it actually a level-scoped object, more like a level actor. What's happening is that because you've registered it as a global object, it gets restored up-front, as one of the first restoration actions. Then, the level gets loaded - but because it's a UWorld scoped object, UE then nukes it again so all the state is lost.

You might be better to store the state in this object in a level actor instead, which can be automatically discovered. It'll have the same scope as the world subsystem, essentially. I've never used a world subsystem before, only a game instance subsystem so I hadn't come across this before. I guess there's an argument for manually registering world-scoped objects that aren't actors, but I think this is pretty niche.

YeNov commented 8 months ago

Yeah, so it appears to not fall into both supported categories - actors and global objects. I did some tests today and just stored needed info into GI Subsystem. Works fine to me