RequestAsyncLoad() Not working?

Hey guys, I am trying to async load an actor in my game’s level but it’s not working, firstly there is some problem with the FStreamableHandle that it’s not valid, the editor kept crashing whenever I stopped the game.

I also get a log message saying RequestAsyncLoad called with NULL assets although I did set the MainMenuCamera to a Camera Actor in the Blueprints.

Please review my code and let me know if there’s any solution would really appreciate it thanks!

// . h file
#pragma once

#include "CoreMinimal.h"
#include "Templates/SharedPointer.h"
#include "GameFramework/GameModeBase.h"
#include "Engine/StreamableManager.h"
#include "GMB_MainMenu.generated.h"



UCLASS()
class TANKMAYHEM_API AGMB_MainMenu : public AGameModeBase
{
    GENERATED_BODY()

public:

    // Sets default values for the game mode (Constructor)
    AGMB_MainMenu();

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;
    
    // Called when the game ends
    virtual void BeginDestroy() override;
    
    // Called to handle game start
    void HandleGameStart();

public:
    
    // Functions:

     // Called Every Frame
     virtual void Tick( float DeltaSeconds ) override;

    // Variables:
    
     TArray<FSoftObjectPath> TargetsToStream;
     
     UPROPERTY(EditDefaultsOnly)
     TSoftObjectPtr<AActor> MainMenuCamera {}; 

private:

    // Functions:
     void LoadSoftReferences();


    // Variables:

     TSharedPtr<FStreamableHandle> LoadSoftObjsHandle;

};
// . cpp file

#include "GMB_MainMenu.h"
#include "Kismet/GameplayStatics.h"
#include "Engine/AssetManager.h"
#include "UObject/SoftObjectPath.h"




AGMB_MainMenu::AGMB_MainMenu()
{
    // Sets whether this class can tick
    PrimaryActorTick.bCanEverTick = true;

}


void AGMB_MainMenu::BeginPlay()
{
    Super::BeginPlay();
    
    // Calls LoadSoftReferences to load all soft referenced objects
    LoadSoftReferences();
}

void AGMB_MainMenu::BeginDestroy()
{
    Super::BeginDestroy();

    if (LoadSoftObjsHandle->IsActive()){

        LoadSoftObjsHandle->CancelHandle();

    }
    
}

void AGMB_MainMenu::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);

}

void AGMB_MainMenu::LoadSoftReferences()
{   
    //TargetsToStream.Add(MainMenuCamera.ToSoftObjectPath());  

   LoadSoftObjsHandle = UAssetManager::GetStreamableManager().RequestAsyncLoad(
    MainMenuCamera.ToSoftObjectPath(),
    FStreamableDelegate::CreateUObject(this, &AGMB_MainMenu::HandleGameStart)
   );

}

void AGMB_MainMenu::HandleGameStart()
{
  // Get the player controller
  APlayerController* PlayerController = UGameplayStatics::GetPlayerController(this, 0);

  if (PlayerController){
    UE_LOG(LogTemp, Warning, TEXT("Player Controller Loaded"));
  }

}

Found the solution! It was because I was doing all of this in a GameModeBase Class, instead I made an Actor C++ class called “GameDirector” and did this in that

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.