sinbad / SPUD

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

Pre / Post Restore calls and BeginPlay order #31

Closed fayth777 closed 2 years ago

fayth777 commented 2 years ago

Hello! Thank you for your work and the great system you have provided. I've been testing your system with streaming levels and saves and I've noticed some things which could cause potential problems in the future and was wondering if you could help.

  1. Pre/Post Restore events do not happen on the first time the sub level is streamed in.
  2. Before save/loading the game pre/post restore is called before begin play of actors on level but after saving/loading the game the order is changed and begin play happens before pre/post restore. This from what I understand forces me to execute the same code twice - on begin play and post restore. Could you maybe provide some information on what you think is the best solution here? Or is there maybe a way to call restores the first time the level is loaded as well? What is the cause of different order of calls after the game is loaded? Thank you very much for your time.
sinbad commented 2 years ago

Warning: I'm on a break over the holidays so this is entirely from memory, on my phone :)

  1. There won't be a pre/post restore the first time the level is streamed simply because there is no data being restored.

  2. Ordering on Begin Play is generally unreliable. However, you can tell whether SPUD is in the middle of a load process (see SpudSubsystem's IsLoading IIRC?) which you can use to tell whether you're going to get a subsequent post-restore call on a stored object. That might help you resolve your duplicate cases.

fayth777 commented 2 years ago

Hey, thanks for the reply! I don't want to bother you too much but when you have time could you suggest what to use instead of begin play for actors on sub level to know that it will be done after data and level is loaded every time the level is streamed in no matter if the data was there or not? Or is checking for isLoading what you would do?

sinbad commented 2 years ago

You can either check IsLoading or determine from your own state (or add a "bIsInitialised" flag) to know when you've already done it. But the core problem might be that you have overlapping responsibilities - state that is both loaded and manually initialised. If possible, move the default state to the constructor instead, or if you can't do that, make whatever it is you're doing safe to do more than once regardless of initialisation route (that's the most robust and can help you with other sequences too like resetting)

fayth777 commented 2 years ago

Ok got it, once again thank you very much!