sinbad / SPUD

Steve's Persistent Unreal Data library
MIT License
337 stars 51 forks source link

Support using built-in UE streaming volumes #12

Closed TI-asilva closed 3 years ago

TI-asilva commented 3 years ago

Move critical pieces of code into public functions so that SPUD can be used with other level streaming mechanisms (including the built-in one in UE4). Also, fix ordering issue with event broadcast.

TI-asilva commented 3 years ago

Hello @sinbad! I implemented the included changes to allow USpudSubsystem to play nicely with the built-in UE streaming volumes (and/or other streaming mechanisms). I think your implementation is more intuitive and easier to understand, but I like the number of development hours that have gone into the existing one and our team already has a bunch of levels that are setup using them, so this is to save them having to go through and convert them all over to SpudStreamingVolumes. Also, we may be moving to UE5 at some point and if we do, there will likely be a push to switch over to their new world partitioning system when that happens and since they (Epic) have an automated commandlet to go from built-in streaming volumes to the new setup, this will make things easier for us in the future as well.

With these changes, all I have to do is hook into these built-in events (in my testbed project, I put them in the game mode class):

FWorldDelegates::LevelAddedToWorld.AddUObject(this, &MyGameMode::OnLevelAddedToWorld);
FWorldDelegates::LevelRemovedFromWorld.AddUObject(this, &MyGameMode::OnLevelRemovedFromWorld);

and then call the respective functions I spliced out in USpudSubsystem in each handler. Regarding the difference in their signatures (i.e. ULevel* vs. FName):

void HandleLevelUnloaded(ULevel* Level);
void HandleLevelLoaded(FName LevelName);

I wanted the code inside them to be identical to the pre-existing code so that it was literally just cutting some code, putting it in a function, and then adding the call to that function. This seemed like the path of least rejection and creates no real difference in the code that's executed by existing users (yourself included). :)

TI-asilva commented 3 years ago

Done. I also adjusted placement of the functions in the .cpp file to more closely mirror their relative locations in the .h file.

sinbad commented 3 years ago

I just quickly fixed up a param ref in the docs & merged. Thanks for the PR!