Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jdsherbert/unreal-engine-async-load-tool

Asynchronous Loading tool for Unreal Engine allowing soft loading of objects freely or with a callback.
https://github.com/jdsherbert/unreal-engine-async-load-tool

async asynchronous asyncloader callback-functions cpp loading module unreal-engine unreal-engine-5

Last synced: 3 months ago
JSON representation

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

Awesome Lists containing this project

README

        

![image](https://user-images.githubusercontent.com/43964243/235778441-9dfb45ab-befd-480b-bc30-5eab5dc2efef.png)

# 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)
```cpp
template
UFUNCTION(BlueprintCallable, Category = "Async Loader")
static void AsyncLoadObject(TSoftObjectPtr SoftPtr, T*& Out_LoadedObject);
```
Attempts to load an asset at a defined path asynchronously, and store it in a variable on completion.
```cpp
// EXAMPLE:
void MyClass::MyFunction()
{
TSoftObjectPtr ObjectSoftPtr = SoftObjectPtrToYourObject;
USomeObject* SomeLoadedObject = nullptr;
UAsyncLoader::AsyncLoadObject(ObjectSoftPtr, SomeLoadedObject);
// Use the loaded object
if (SomeLoadedObject != nullptr) // Always check for nullptrs on asyncloaded objects
{
// Do something with the loaded object
}
}
```

2. With Callback
```cpp
template
UFUNCTION(BlueprintCallable, Category = "Async Loader")
static void AsyncLoadObject(TSoftObjectPtr 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.
```cpp
// 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 ObjectSoftPtr = SoftObjectPtrToYourObject;
UAsyncLoader::AsyncLoadObject(ObjectSoftPtr, &MyLoadCompleteCallback);
}
```

-----------------------------------------------------------------------