Skip to content

Instantly share code, notes, and snippets.

@MauritsDijkman
Created January 27, 2024 11:29
Show Gist options
  • Save MauritsDijkman/e9f356e6a1b83d1c3e4606b1ca7e899b to your computer and use it in GitHub Desktop.
Save MauritsDijkman/e9f356e6a1b83d1c3e4606b1ca7e899b to your computer and use it in GitHub Desktop.
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Components/SceneComponent.h"
#include "AsyncLevelLoadSceneComponent.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnLevelLoadedDelegate_ASync);
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnLevelLoadedDelegate_Streaming);
UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))
class VREXPPLUGINEXAMPLE_API UAsyncLevelLoadSceneComponent : public USceneComponent
{
GENERATED_BODY()
public:
// Async
UPROPERTY(BlueprintAssignable, Category = "AsyncLevelLoad")
FOnLevelLoadedDelegate_ASync OnLevelLoadedDelegate_Async;
UFUNCTION(BlueprintCallable, Category = "AsyncLevelLoad")
void AsyncLevelLoad(const FString& LevelDir, const FString& LevelName);
UFUNCTION(BlueprintCallable, Category = "AsyncLevelLoad")
void OpenLoadedLevel();
// Streaming
UPROPERTY(BlueprintAssignable, Category = "StreamLevelLoad")
FOnLevelLoadedDelegate_Streaming OnLevelLoadedDelegate_Streaming;
UFUNCTION(BlueprintCallable, Category = "StreamLevelLoad")
void StreamLevelLoad(const FString& LevelNameToLoad, const FString& LevelNameToUnload);
UFUNCTION()
void OnStreamLevelLoaded();
private:
FString GetLoadingResultString(EAsyncLoadingResult::Type Result);
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
public:
// Sets default values for this component's properties
UAsyncLevelLoadSceneComponent();
UPROPERTY(BlueprintReadOnly, Category = "AsyncLevelLoad")
float loadingPercentage;
private:
// Async
FString pLevelDir;
FString pLevelName;
EAsyncLoadingResult::Type pResult;
bool bIsLoading;
// Streaming
FString pLevelNameToUnload;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment