RecordSavedGameData() blocking the main thread
Posted: Wed Dec 14, 2022 9:47 pm
Whenever my game saves it blocks the main thread for a brief second or so. I'm already spawning a separate thread for the actual file writing but no help. So I profiled what the problem was and it was RecordSavedGameData(), most of which is the DialogueSystemSaver generating a very large string for all the variables etc. Even though it is running out of a coroutine, no help because there's never a yield in there so it just runs for a long time without yielding back.
The duration it takes to save doesn't bug me, but how do I go about getting this to not block somehow? I already tried tossing RecordSavedGameData onto a separate thread, but it uses too many Unity API calls and Unity disallows those unless on the main thread. Would I have to somehow split up this method with yields? Problem there is if I yield per every single variable write, that's way too many and it will take ages to actually save. I suppose I could do an arbitrary number of em and chunk em out, then yield after each chunk.... If it comes down to that, I'll have to do it, but wondering if you have any good tips on this. Thanks.
The duration it takes to save doesn't bug me, but how do I go about getting this to not block somehow? I already tried tossing RecordSavedGameData onto a separate thread, but it uses too many Unity API calls and Unity disallows those unless on the main thread. Would I have to somehow split up this method with yields? Problem there is if I yield per every single variable write, that's way too many and it will take ages to actually save. I suppose I could do an arbitrary number of em and chunk em out, then yield after each chunk.... If it comes down to that, I'll have to do it, but wondering if you have any good tips on this. Thanks.