SPUD icon indicating copy to clipboard operation
SPUD copied to clipboard

WorldSubsystem property saving issue

Open YeNov opened this issue 2 years ago • 2 comments

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

  • World Subsystem Subclass (WSS) added as named global object
  • WSS has a uobject with a TMap<CustomStruct1, CustomStruct2>
  • When loading, during PostRestore, everything seems fine, but after that world gets cleared and on PostLoad WSS is a brand new instance and uobject property is null'ed

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

YeNov avatar Nov 01 '23 09:11 YeNov

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.

sinbad avatar Nov 01 '23 15:11 sinbad

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

YeNov avatar Nov 01 '23 15:11 YeNov