반응형

Hi,

It's much easier to manage level streaming in blueprints instead of C++.
Take a look at GetStreamingLevel BP node. It gives you full control over level streaming.

Name:  levelstreaming_1.png
Views: 1840
Size:  55.4 KB

Name:  levelstreaming_2.png
Views: 1843
Size:  59.8 KB




Thread: Level streaming with C++

https://forums.unrealengine.com/showthread.php?26581-Level-streaming-with-C
  1. #1
    0
    Supporter
    Join Date
    Aug 2014
    Posts
    4

     [SOLVED] Level streaming with C++

    Hi everyone ,

    I have a short question (or long).

    I have now searched for hours and tested some code but I can't find information about correct level streaming with C++.

    What I want to do is:

    I have 2 maps ("map1", "map2", "this" is a class derived from"AActor"). 

    Code:
    ....
    //sample code for used class
    UClass()
    class Test : public AActor {
      .....
      public:
         void test();  
      ....
    }
    At first I call: 

    Code:
    //FLatentActionInfo isn't document well what it does and when, or I can't find enough information about it
    UGameplayStatics::LoadStreamLevel(this, "map1", true, true, FLatentActionInfo())
    Later ingame "ENTER" is pressed and I want to stream another level, as I had done it with blueprints before for testing.

    Code:
    UGameplayStatics::LoadStreamLevel(this, "map2", true, true, FLatentActionInfo()) 
    UGameplayStatics::UnloadStreamLevel(this, "map1", FLatentActionInfo())
    The first call loads the map correctly. The second call for "map2" loads also correctly but then the "map1" isn't unloaded. The documentation says that the next call isn't processed until the first call is finished ("Stream the level with the LevelName ; Calling again before it finishes has no effect.").

    The should be the point why "map1" isn't unloaded because "map2" is currently loaded and not finished at this point.

    I also tried to fill the FLatentActionInfo struct with

    Code:
    FLatentActionInfo info;
    info.CallbackTarget=this;
    info.ExecutionFunction="test";
    info.UUID=12345;
    and called 

    Code:
    UGameplayStatics::LoadStreamLevel(this, "map1", true, true, info)
    I expected that the callback is called if the loading operation was done but the method "test" is never called.

    So I wondering about how I can achive it.

    If anyone could explain this for me it would be really really great or have a short information which points in the correct direction.

    Thank you in advance and have a nice day so far.

    Regards

    -freakxnet
    Last edited by freakxnet; 08-05-2014 at 06:34 PM.
    Quick reply to this messageReply   Reply With QuoteReply With Quote   Multi-Quote This Message     
  2. #2
    0
    Unreal Engine Developer
    Join Date
    Mar 2014
    Posts
    101
    Hi,

    It's much easier to manage level streaming in blueprints instead of C++.
    Take a look at GetStreamingLevel BP node. It gives you full control over level streaming.

    Name:  levelstreaming_1.png
Views: 1840
Size:  55.4 KB

    Name:  levelstreaming_2.png
Views: 1843
Size:  59.8 KB
    Quick reply to this messageReply   Reply With QuoteReply With Quote   Multi-Quote This Message     
  3. #3
    0
    Supporter
    Join Date
    Aug 2014
    Posts
    4

     !!!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:

    Code:
    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. 

    Code:
    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.

    Code:
    FLatenActionInfo info;
    info.CallbackTarget = *myObjectWithDerivesFromUObject;
    info.ExecutionFunction = "m


반응형

+ Recent posts