Level streaming with C++

!!!solved!!!

Thank you for your post. With blueprints the streaming isn’t a problem. So but I want to have it in Code ;-).

So for all who wants to integrate level streaming within C++ code here’s the solution:

I thought about the callback function of the FLatentActionInfo structure.
You have to define:



FLatenActionInfo info;
info.CallbackTarget = *myObjectWithDerivesFromUObject;
info.ExecutionFunction = "myFunctionToCall";
info.UUID = 1;
info.Linkage = 0;


Normally you would give a function pointer to got access to a callback method. But here you give a method name String. Now for Java, when I does reflection related stuff I use often strings for method / member access. Also for this problem. A string to use is only possible if the method name is resolved by the reflection system.

Then the solution is easy:

You have to define the method within the UE4 reflection system. After I had added the UFUNCTION macro the method was instantly called.




UCLASS()
class TestClass : public AActor {
    public:
       UFUNCTION(BlueprintCallable, Category = Game)
       void myFunctionToCall();

};


Now this is possible:

load “map1” => callback1 => unload “map1” => callback => load “map2” and voila it’s done. The content of “map1” is disappeared and only “map2” stays loaded.

Wrapped into a new controller class its now a simple task to stream levels. But don’t forget to add them within UE4 => MainMenu:Window => Levels.



FLatenActionInfo info;
info.CallbackTarget = *myObjectWithDerivesFromUObject;
info.ExecutionFunction = "myFunctionToCall";
info.UUID = 1;
info.Linkage = 0;

UGameplayStatics::LoadStreamLevel(this, "map1", true, true, info)


Regards

-freakxnet

7 Likes