4#include "VRBaseCharacter.h"
5#include "Engine/LevelStreaming.h"
11#include "Kismet/GameplayStatics.h"
22 static const FString ContextString(TEXT(
"StreamingLevels"));
27 if (RowNames.Num() == 0)
29 UE_LOG(LogTemp, Error, TEXT(
"LevelStreamingDataTable is empty!"))
30 return TArray<FName>();
33 for (
const auto RowName : RowNames)
36 if (FoundLevels->
StepName.EqualTo(StepName))
48 UE_LOG(LogTemp, Error, TEXT(
"LevelStreamingDataTable is invalid!"));
50 return TArray<FName>();
56 if (levelsToLoad.Num() == 0)
64 for (FName level : levelsToLoad)
79 if (levelsToLoad.Num() != 0)
88 auto FadeInFinishedEvent = [
this]()
111 auto FadeInFinishedEvent = [
this]()
133 UE_LOG(LogTemp, Log, TEXT(
"Levels to load array is empty!"));
146 auto SetVisibilityEvent = [
this, Visible, Levels]()
148 for (FName Level : Levels)
150 UGameplayStatics::GetStreamingLevel(GetWorld(), Level)->SetShouldBeVisible(Visible);
160 SetVisibilityEvent();
189 AVRBaseCharacter* Character = Cast<AVRBaseCharacter>( UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
206 FLatentActionInfo LatentInfo;
207 LatentInfo.CallbackTarget =
this;
208 LatentInfo.ExecutionFunction =
"LevelUnloaded";
209 LatentInfo.Linkage = 1;
210 LatentInfo.UUID = IndexToUnload;
212 UGameplayStatics::UnloadStreamLevel(
this,
LevelsToUnload[IndexToUnload], LatentInfo,
false);
224 AVRBaseCharacter* Character = Cast<AVRBaseCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
240 FLatentActionInfo LatentInfo;
241 LatentInfo.CallbackTarget =
this;
242 LatentInfo.ExecutionFunction =
"LevelLoaded";
243 LatentInfo.Linkage = 1;
244 LatentInfo.UUID = IndexToLoad;
246 UGameplayStatics::LoadStreamLevel(
this,
LevelsToLoad[IndexToLoad],
true,
true, LatentInfo);
#define DEFINE_EVENT_HANDLER(TEventType)
static FUNCTION_NON_NULL_RETURN_START TEventType * NewEvent(APlayerController *Executor=nullptr) FUNCTION_NON_NULL_RETURN_END
Creates a new event of the specified type.
void HandleEvent_Impl(class UBaseEvent *Event)
Event called when new step is loaded.
Event called when new story is loaded.
void SetLevelsVisibility(TArray< FName > Levels, bool Visible)
UFUNCTION(BlueprintCallable, Category = "LevelStreamingManager")
void LevelLoaded()
UFUNCTION()
TArray< FName > LevelsToLoad
Array storing the levels to load.
void LevelUnloaded()
UFUNCTION()
TArray< FName > LoadedLevels
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "LevelStreamingManager")
TArray< FName > LevelsToUnload
Array storing the levels to unload.
void LoadStreamingLevels(TArray< FName > levelsToLoad, bool onlyFadeOut=false, float FadeTime=0.5f)
Calling due to LevelStreamingDataTable, but you also can call it manually. In addition,...
void LoadStreamingLevelsAndTeleportPlayer(TArray< FName > Levels, FTransform PlayerTransform, bool OnlyFadeOut=false, float FadeTime=0.5f)
Call it manually, if you want to teleport player to specific location after loading levels.
void UnloadStreamingLevels(int32 IndexToUnload)
This function unloads a specific streaming level based on the provided index.
void FilteredArraysToLoadUnload(TArray< FName > levelsToLoad)
This function takes an array of levels to load and filters the arrays LevelsToLoad and LevelsToUnload...
TArray< FName > GetLevelsBasedOnStep(FText StepName)
UFUNCTION(BlueprintCallable, Category = "LevelStreamingManager")
UDataTable * LevelStreamingDataTable
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LevelStreamingManager")
bool AutoFadeInAndOut
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "LevelStreamingManager")
int32 LoadingIndex
Index for tracking the loading progress.
FTransform PlayerNewTransform
Transform representing the new location for the player after loading levels.
int32 UnloadingIndex
Index for tracking the unloading progress.
float TimeForFades
Time duration for fade effects.
bool TeleportPlayerToSpecificLocation
Determines whether to teleport the player to a specific location after loading levels.
FText StepName
UPROPERTY(BlueprintReadWrite, EditAnywhere)
Structure representing streaming levels to load based on step. Also contains info about new player po...
bool TeleportPlayerToSpecificLocation
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray< FName > ActiveLevels
UPROPERTY(EditAnywhere, BlueprintReadOnly)
FText StepName
UPROPERTY(EditAnywhere, BlueprintReadOnly)
FTransform PlayerNewLocation
UPROPERTY(EditAnywhere, BlueprintReadWrite)