Skip to content

Asynchronous Loading tool for Unreal Engine allowing soft loading of objects freely or with a callback.

License

Notifications You must be signed in to change notification settings

JDSherbert/Unreal-Engine-Async-Load-Tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 

Repository files navigation

image

Unreal Engine Async Load Tool

Stars Badge Forks Badge Watchers Badge Issues Badge


Unreal Engine Tool License




Overview

Compact Blueprint Function Library class that contains a set of static functions that makes asynchronous loading of UObjects more unified and easier to do. Utilizes the internal streaming assets manager and throwaway lambda callbacks. Note that this is naturally latent, so always assess the validity of the asynchronously loaded object before use.

These functions are also available in blueprint!


Why Asynchronously Load Anything?

Loading game assets asynchronously offers several benefits:

  • Reduced Loading Times: We can preload what we need!
  • Improved Responsiveness: Asynchronous loading helps prevent the main thread from being blocked, allowing other processes to continue unimpeded.
  • Optimized Resource Usage: Loading assets asynchronously allows for better management of system resources and optimization.
  • Dynamic Loading and Unloading: Assets can be loaded or unloaded based on the player's location or progression, helping to conserve resources.
  • Streaming and Seamless Transitions: Asynchronous loading supports streaming of assets, allowing for seamless transitions between different parts of the game world. This is essential for maintaining a continuous and immersive experience without noticeable interruptions or loading screens.
  • Parallel Processing: While one set of assets is being loaded, other game-related tasks can be performed simultaneously, maximizing the utilization of available hardware resources.
  • Adaptability to Varying Hardware: Stability and resource delegation.

In summary, loading game assets asynchronously contributes to a more responsive, efficient, and immersive gaming experience, particularly in scenarios where large and dynamic game worlds are involved.


Using the Tool

First, implement the this gameplay module into your project.

Then, there are two ways to load with the tool:

  1. Without Callback (Pointer Only)
    template<class T = UObject>
    UFUNCTION(BlueprintCallable, Category = "Async Loader")
    static void AsyncLoadObject(TSoftObjectPtr<T> SoftPtr, T*& Out_LoadedObject);

Attempts to load an asset at a defined path asynchronously, and store it in a variable on completion.

// EXAMPLE:
void MyClass::MyFunction()
{ 
    TSoftObjectPtr<USomeObject> ObjectSoftPtr = SoftObjectPtrToYourObject;
    USomeObject* SomeLoadedObject = nullptr;
    UAsyncLoader::AsyncLoadObject<USomeObject>(ObjectSoftPtr, SomeLoadedObject);
    // Use the loaded object
    if (SomeLoadedObject != nullptr) // Always check for nullptrs on asyncloaded objects
    {
        // Do something with the loaded object
    }
}
  1. With Callback
    template<class T = UObject>
    UFUNCTION(BlueprintCallable, Category = "Async Loader")
    static void AsyncLoadObject(TSoftObjectPtr<T> SoftPtr, void(*Callback)(T* LoadedObject));

Attempts to load an asset at a defined path asynchronously. Will call the supplied function pointer on success, passing the loaded object pointer as a parameter. Useful if you want to be notified when the load is completed.

// EXAMPLE:
void MyClass::MyLoadCompleteCallback(UObject* LoadedObject)
{
    // Handle the loaded object
    if (LoadedObject != nullptr) // Always check for nullptrs on asyncloaded objects
    {
        // Do something with the loaded object
    }
}

void MyClass::MyFunction()
{
    TSoftObjectPtr<UObject> ObjectSoftPtr = SoftObjectPtrToYourObject;
    UAsyncLoader::AsyncLoadObject(ObjectSoftPtr, &MyLoadCompleteCallback);
}

About

Asynchronous Loading tool for Unreal Engine allowing soft loading of objects freely or with a callback.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published