MultiWorld 1.9.1
Manage multiple isolated UWorld instances simultaneously in Unreal Engine, transferring player and actors between worlds.
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
UMultiWorldStatics Class Reference

Static class with MultiWorld functions that can be called from both Blueprint and C++. More...

#include <MultiWorldStatics.h>

Inheritance diagram for UMultiWorldStatics:

Static Public Member Functions

static bool AreWorldsEquals (const FMultiWorldHandle &InWorldHandleA, const FMultiWorldHandle &InWorldHandleB)
 Return true if the two world handle(s) are equals (they refer to the same world), false otherwise. More...
 
static void EndWorld (const UObject *WorldContextObject, const FMultiWorldHandle &InWorldHandle)
 Call the EndPlay to the input World and to all its actors; The World and all actors are destroyed. More...
 
static void ExecuteConsoleCommandInWorld (const FMultiWorldHandle &InWorldHandle, const FString &Command)
 Executes a console command on a specific world. More...
 
static FMultiWorldHandle GetActiveWorldHandle (const UObject *WorldContextObject)
 Return the world handle of the active World. More...
 
static class AActor * GetActorOfClass (const FMultiWorldHandle &InWorldHandle, TSubclassOf< AActor > ActorClass)
 Find the first Actor in the world of the specified class. More...
 
static void GetAllActorsOfClass (const FMultiWorldHandle &InWorldHandle, TSubclassOf< AActor > ActorClass, TArray< AActor * > &OutActors)
 Find all Actors in the world of the specified class. More...
 
static void GetAllActorsOfClassWithTag (const FMultiWorldHandle &InWorldHandle, TSubclassOf< AActor > ActorClass, FName Tag, TArray< AActor * > &OutActors)
 Find all Actors in the world of the specified class with the specified tag. More...
 
static void GetAllActorsWithInterface (const FMultiWorldHandle &InWorldHandle, TSubclassOf< UInterface > Interface, TArray< AActor * > &OutActors)
 Find all Actors in the world with the specified interface. More...
 
static void GetAllActorsWithTag (const FMultiWorldHandle &InWorldHandle, FName Tag, TArray< AActor * > &OutActors)
 Find all Actors in the world with the specified tag. More...
 
static void GetAllObjectsWithInterface (const FMultiWorldHandle &InWorldHandle, TSubclassOf< UInterface > Interface, TArray< UObject * > &OutObjects)
 Find all UObject(s) in the world with the specified interface. More...
 
static FMultiWorldHandle GetMainWorldHandle (const UObject *WorldContextObject)
 Return the main world handle. More...
 
static class APlayerController * GetPlayerController (const UObject *WorldContextObject, int32 PlayerIndex)
 Returns the player controller found while iterating through the local available player controllers. More...
 
static FMultiWorldHandle GetThisWorldHandle (const UObject *WorldContextObject)
 Return the world handle where the caller lives. More...
 
static FMultiWorldHandle GetWorldHandleByName (const UObject *WorldContextObject, FName WorldName)
 Return the world handle of the world with the given name if found or an invalid handle otherwise. More...
 
static void InitializeWorld (const UObject *WorldContextObject, const FMultiWorldHandle &InWorldHandle)
 Setup the input World for playing; Actors are intialized, BeginPlay is called etc... After you call this method, you can switch world calling SwitchWorld. More...
 
static bool IsValidHandle (const UObject *WorldContextObject, const FMultiWorldHandle &InWorldHandle)
 Return true if the input world handle is valid, false otherwise. More...
 
static void LoadWorldAsyncWithDelegate (const UObject *WorldContextObject, TSoftObjectPtr< UWorld > InMapAsset, FMultiWorldLoadParameters InParams, FOnLoadWorldCompletedDelegateSimple OnComplete)
 Asynchronously load a World into memory. More...
 
static void LoadWorldWithDelegate (const UObject *WorldContextObject, TSoftObjectPtr< UWorld > InMapAsset, FMultiWorldLoadParameters InParams, FOnLoadWorldCompletedDelegateSimple OnComplete)
 Synchronously load a World into memory. More...
 
static void RequestSwitchWorld (const UObject *WorldContextObject, const FMultiWorldHandle &InWorldHandle)
 Like SwitchWorld() but the switch will take place in the next frame and outside the worlds ticking. More...
 
static bool ReturnToMainWorld (const UObject *WorldContextObject)
 Travel the local players to the main world. More...
 
static void SetAutoHandleWidgetsForMainWorld (const UObject *WorldContextObject, bool bAutoHandleWidgets)
 Sets whenever the UMG main world widgets must be handled automatically or not (shown when the world is active, hidden when the world is not). More...
 
static void SetPhysicsActorTransform (AActor *Actor, const FTransform &NewTransform, ETeleportType Teleport=ETeleportType::ResetPhysics)
 Set the Actor transform, moving also all attached physics bodies as a single entity. More...
 
static void SetShouldTickWhenInBackground (const UObject *WorldContextObject, const FMultiWorldHandle &InWorldHandle, bool bShouldTick)
 Sets whether or not the input world is ticked by the engine when it is in background (when not in play). More...
 
static AActor * SpawnActorInWorld (const UObject *WorldContextObject, TSubclassOf< class AActor > ActorClass, const FMultiWorldHandle &InWorldHandle, const FTransform &SpawnTransform, ESpawnActorCollisionHandlingMethod CollisionHandlingOverride, AActor *Owner)
 Create an actor and place it in the input world. More...
 
static bool SwitchWorld (const UObject *WorldContextObject, const FMultiWorldHandle &InWorldHandle)
 Change the Active World, travelling the local players to the input world. More...
 
static void TransferActorToWorld (const UObject *WorldContextObject, AActor *InActor, const FMultiWorldHandle &InWorldHandle, const FMultiWorldTransferActorParameters &Options)
 Transfer the input actor from its actual world to the input one. More...
 

Detailed Description

Static class with MultiWorld functions that can be called from both Blueprint and C++.

Few extra features (mainly Delegates) are available using the UMultiWorldManager subsystem.

Member Function Documentation

◆ AreWorldsEquals()

static bool UMultiWorldStatics::AreWorldsEquals ( const FMultiWorldHandle InWorldHandleA,
const FMultiWorldHandle InWorldHandleB 
)
static

Return true if the two world handle(s) are equals (they refer to the same world), false otherwise.

Parameters
[in]InWorldHandleAfirst world handle to compare
[in]InWorldHandleBsecond world handle to compare

◆ EndWorld()

static void UMultiWorldStatics::EndWorld ( const UObject *  WorldContextObject,
const FMultiWorldHandle InWorldHandle 
)
static

Call the EndPlay to the input World and to all its actors; The World and all actors are destroyed.

The input world handle is not more valid after. If InWorldHandle is the active world (equals to GetActiveWorldHandle()), ReturnToMainWorld is called automatically. Can NOT be called with the main world handle (GetMainWorldHandle() is not a valid param). In this case the call doesn't have any effect.

Parameters
[in]WorldContextObjectthe world context object
InWorldHandlethe world handle

◆ ExecuteConsoleCommandInWorld()

static void UMultiWorldStatics::ExecuteConsoleCommandInWorld ( const FMultiWorldHandle InWorldHandle,
const FString &  Command 
)
static

Executes a console command on a specific world.

Parameters
InWorldHandleThe handle of the world where to exec the command
CommandCommand to send to the console

◆ GetActiveWorldHandle()

static FMultiWorldHandle UMultiWorldStatics::GetActiveWorldHandle ( const UObject *  WorldContextObject)
static

Return the world handle of the active World.

Parameters
[in]WorldContextObjectthe world context object

◆ GetActorOfClass()

static class AActor * UMultiWorldStatics::GetActorOfClass ( const FMultiWorldHandle InWorldHandle,
TSubclassOf< AActor >  ActorClass 
)
static

Find the first Actor in the world of the specified class.

This is a slow operation, use with caution e.g. do not use every frame.

Parameters
InWorldHandleThe handle of the world where find the actor.
ActorClassClass of Actor to find. Must be specified or result will be empty.
Returns
Actor of the specified class.

◆ GetAllActorsOfClass()

static void UMultiWorldStatics::GetAllActorsOfClass ( const FMultiWorldHandle InWorldHandle,
TSubclassOf< AActor >  ActorClass,
TArray< AActor * > &  OutActors 
)
static

Find all Actors in the world of the specified class.

This is a slow operation, use with caution e.g. do not use every frame.

Parameters
InWorldHandleThe handle of the world where find the actors.
ActorClassClass of Actor to find. Must be specified or result array will be empty.
OutActorsOutput array of Actors of the specified class.

◆ GetAllActorsOfClassWithTag()

static void UMultiWorldStatics::GetAllActorsOfClassWithTag ( const FMultiWorldHandle InWorldHandle,
TSubclassOf< AActor >  ActorClass,
FName  Tag,
TArray< AActor * > &  OutActors 
)
static

Find all Actors in the world of the specified class with the specified tag.

This is a slow operation, use with caution e.g. do not use every frame.

Parameters
InWorldHandleThe handle of the world where find the actors.
TagTag to find. Must be specified or result array will be empty.
ActorClassClass of Actor to find. Must be specified or result array will be empty.
OutActorsOutput array of Actors of the specified tag.

◆ GetAllActorsWithInterface()

static void UMultiWorldStatics::GetAllActorsWithInterface ( const FMultiWorldHandle InWorldHandle,
TSubclassOf< UInterface >  Interface,
TArray< AActor * > &  OutActors 
)
static

Find all Actors in the world with the specified interface.

This is a slow operation, use with caution e.g. do not use every frame.

Parameters
InWorldHandleThe handle of the world where find the actors.
InterfaceInterface to find. Must be specified or result array will be empty.
OutActorsOutput array of Actors of the specified interface.

◆ GetAllActorsWithTag()

static void UMultiWorldStatics::GetAllActorsWithTag ( const FMultiWorldHandle InWorldHandle,
FName  Tag,
TArray< AActor * > &  OutActors 
)
static

Find all Actors in the world with the specified tag.

This is a slow operation, use with caution e.g. do not use every frame.

Parameters
InWorldHandleThe handle of the world where find the actors.
TagTag to find. Must be specified or result array will be empty.
OutActorsOutput array of Actors of the specified tag.

◆ GetAllObjectsWithInterface()

static void UMultiWorldStatics::GetAllObjectsWithInterface ( const FMultiWorldHandle InWorldHandle,
TSubclassOf< UInterface >  Interface,
TArray< UObject * > &  OutObjects 
)
static

Find all UObject(s) in the world with the specified interface.

This is a slow operation, use with caution e.g. do not use every frame.

Parameters
InWorldHandleThe handle of the world where find the actors.
InterfaceInterface to find. Must be specified or result array will be empty.
OutObjectsOutput array of UObject(s) of the specified interface.

◆ GetMainWorldHandle()

static FMultiWorldHandle UMultiWorldStatics::GetMainWorldHandle ( const UObject *  WorldContextObject)
static

Return the main world handle.

The main world is the world loaded by the Unreal Engine itself.

Parameters
[in]WorldContextObjectthe world context object

◆ GetPlayerController()

static class APlayerController * UMultiWorldStatics::GetPlayerController ( const UObject *  WorldContextObject,
int32  PlayerIndex 
)
static

Returns the player controller found while iterating through the local available player controllers.

The implementation is equal to UGameplayStatics::GetPlayerController (UE 4.26)

WARNING: the new implementation of UGameplayStatics::GetPlayerController (UE 5.03) get the player controller from the localplayer and this is wrong when it's called outside the world tick (e.g delegates). So in UE5 this function must be used instead of UGameplayStatics::GetPlayerController whenever you need to get the player controller in a world but the caller comes from a different world.

Parameters
[in]WorldContextObjectthe world context object
[in]PlayerIndexthe local player index for which to return the player controller

◆ GetThisWorldHandle()

static FMultiWorldHandle UMultiWorldStatics::GetThisWorldHandle ( const UObject *  WorldContextObject)
static

Return the world handle where the caller lives.

Technically it's the UWorld of the World Context Object implicitly passed by UE5 to the function.

Parameters
[in]WorldContextObjectthe world context object

◆ GetWorldHandleByName()

static FMultiWorldHandle UMultiWorldStatics::GetWorldHandleByName ( const UObject *  WorldContextObject,
FName  WorldName 
)
static

Return the world handle of the world with the given name if found or an invalid handle otherwise.

If two or more worlds have the same name, the first found is returned.

Parameters
[in]WorldContextObjectthe world context object
[in]WorldNamethe name of the world to looking for

◆ InitializeWorld()

static void UMultiWorldStatics::InitializeWorld ( const UObject *  WorldContextObject,
const FMultiWorldHandle InWorldHandle 
)
static

Setup the input World for playing; Actors are intialized, BeginPlay is called etc... After you call this method, you can switch world calling SwitchWorld.

Parameters
[in]WorldContextObjectthe world context object
InWorldHandlethe world to setup; it should came from the function LoadWorld.

◆ IsValidHandle()

static bool UMultiWorldStatics::IsValidHandle ( const UObject *  WorldContextObject,
const FMultiWorldHandle InWorldHandle 
)
static

Return true if the input world handle is valid, false otherwise.

Parameters
[in]WorldContextObjectthe world context object
[in]InWorldHandlethe world handle to check

◆ LoadWorldAsyncWithDelegate()

static void UMultiWorldStatics::LoadWorldAsyncWithDelegate ( const UObject *  WorldContextObject,
TSoftObjectPtr< UWorld >  InMapAsset,
FMultiWorldLoadParameters  InParams,
FOnLoadWorldCompletedDelegateSimple  OnComplete 
)
static

Asynchronously load a World into memory.

The map and related assets are loaded asynchronously, using LoadPackageAsync().

In addition to the OnComplete delegate, you can also use the delegate UMultiWorldManager::OnLoadWorldCompleted to be notified when the load is completed.

Attention
Be aware that the loaded world exists only on the local client and is not replicated.
Attention

To load data asynchronously, the project setting "Async Loading Thread Enabled" MUST be enabled (under section "Engine - Streaming") and project data MUST be cooked.

You can also enable the flag adding in DefaultEngine.ini:

[/Script/Engine.StreamingSettings]
s.AsyncLoadingThreadEnable=true
Parameters
[in]WorldContextObjectthe world context object
InMapAssetthe map asset where the World is located.
InParamsoptional params to customize the loading.
OnCompletedelegate called on loading complete.
See also
UMultiWorldManager::LoadWorld() or LoadWorldWithDelegate() to load a world synchronously.
FMultiWorldLoadParameters to customize the loading.

◆ LoadWorldWithDelegate()

static void UMultiWorldStatics::LoadWorldWithDelegate ( const UObject *  WorldContextObject,
TSoftObjectPtr< UWorld >  InMapAsset,
FMultiWorldLoadParameters  InParams,
FOnLoadWorldCompletedDelegateSimple  OnComplete 
)
static

Synchronously load a World into memory.

This is a blocking call, that do most of its job in the game thread and completes its activity before the end of the current engine frame. To guarantee a proper initialization of the loaded UWorld, some initializations could have to be deferred later in the current engine frame. The OnComplete callback will be called as soon as the initialization is done.

In particular, if this method is called during the BeginPlay of the current world (aka the Active World), the OnComplete callback will be activated soon after the BeginPlay ends.

Attention
Be aware that the loaded world exists only on the local client and is not replicated.
Parameters
[in]WorldContextObjectthe world context object
InMapAssetthe map asset where the World is located.
InParamsoptional params to customize the loading.
OnCompletedelegate called on loading complete.
See also
UMultiWorldManager::LoadWorldAsync() or LoadWorldAsyncWithDelegate() to load a world asynchronously.
FMultiWorldLoadParameters to customize the loading.

◆ RequestSwitchWorld()

static void UMultiWorldStatics::RequestSwitchWorld ( const UObject *  WorldContextObject,
const FMultiWorldHandle InWorldHandle 
)
static

Like SwitchWorld() but the switch will take place in the next frame and outside the worlds ticking.

Parameters
[in]WorldContextObjectthe world context object
InWorldHandlethe world handle where to go

◆ ReturnToMainWorld()

static bool UMultiWorldStatics::ReturnToMainWorld ( const UObject *  WorldContextObject)
static

Travel the local players to the main world.

The main world is the world loaded by the Unreal Engine itself. If you call from the main world, the call doesn't have any effect.

Parameters
[in]WorldContextObjectthe world context object
Returns
true if succeeded, false otherwise

◆ SetAutoHandleWidgetsForMainWorld()

static void UMultiWorldStatics::SetAutoHandleWidgetsForMainWorld ( const UObject *  WorldContextObject,
bool  bAutoHandleWidgets 
)
static

Sets whenever the UMG main world widgets must be handled automatically or not (shown when the world is active, hidden when the world is not).

True by default.

Parameters
[in]WorldContextObjectthe world context object
[in]bAutoHandleWidgetstrue if widgets are handled automatically for the main world, false otherwise.

◆ SetPhysicsActorTransform()

static void UMultiWorldStatics::SetPhysicsActorTransform ( AActor *  Actor,
const FTransform &  NewTransform,
ETeleportType  Teleport = ETeleportType::ResetPhysics 
)
static

Set the Actor transform, moving also all attached physics bodies as a single entity.

Parameters
ActorThe Actor to move.
NewTransformThe new transform.
TeleportHow we teleport the physics state (see AActor::SetActorTransform()).

◆ SetShouldTickWhenInBackground()

static void UMultiWorldStatics::SetShouldTickWhenInBackground ( const UObject *  WorldContextObject,
const FMultiWorldHandle InWorldHandle,
bool  bShouldTick 
)
static

Sets whether or not the input world is ticked by the engine when it is in background (when not in play).

Attention
You MUST NOT disable the background ticking of the Main World in a multi-player game.
Parameters
[in]WorldContextObjectthe world context object
InWorldHandlethe world handle for which to apply the setting
bShouldTickthe "tick-when-in-background" flag

◆ SpawnActorInWorld()

static AActor * UMultiWorldStatics::SpawnActorInWorld ( const UObject *  WorldContextObject,
TSubclassOf< class AActor >  ActorClass,
const FMultiWorldHandle InWorldHandle,
const FTransform &  SpawnTransform,
ESpawnActorCollisionHandlingMethod  CollisionHandlingOverride,
AActor *  Owner 
)
static

Create an actor and place it in the input world.

Parameters
[in]WorldContextObjectthe world context object
[in]ActorClassthe class to use to create the actor
[in]InWorldHandlethe world where to place the actor
[in]SpawnTransformthe absolute world transform of the new actor
[in]CollisionHandlingOverridethe strategy for handling the case of collision when the actor is spawned
[in]Ownerthe owner of the new actor
Returns
the new created actor

◆ SwitchWorld()

static bool UMultiWorldStatics::SwitchWorld ( const UObject *  WorldContextObject,
const FMultiWorldHandle InWorldHandle 
)
static

Change the Active World, travelling the local players to the input world.

Secondary Worlds are not replicated.

All actors implementing the interface IMultiWorldActorInterface are notified accordingly to the interface.

The delegate UMultiWorldManager::OnWorldSwitched is notified.

UMG widgets are managed accordingly to the configuration (see FMultiWorldLoadParameters::bAutoHandleWidgets and SetAutoHandleWidgetsForMainWorld()).

Parameters
[in]WorldContextObjectthe world context object
InWorldHandlethe world handle where to go
Returns
true if succeeded, false otherwise

◆ TransferActorToWorld()

static void UMultiWorldStatics::TransferActorToWorld ( const UObject *  WorldContextObject,
AActor *  InActor,
const FMultiWorldHandle InWorldHandle,
const FMultiWorldTransferActorParameters Options 
)
static

Transfer the input actor from its actual world to the input one.

It's not network-replicated.

Attention
While the method UMultiWorldStatics::TransferActorToWorld() provides a convenient way to transfer an actor between different UWorld instances, and its implementation is generic enough to manage most common cases, particular actor setups or advanced uses could require a different and manual procedure. In this case, the suggested approach is to serialize the actor from the source World into a temporary buffer, destroy the actor and create a new instance in the destination World (e.g. using UMultiWorldStatics::SpawnActorInWorld()), finally restoring its state from the serialized data.
Parameters
[in]WorldContextObjectthe world context object
InActorthe actor to transfer
InWorldHandlethe new world of the input actor
OptionsOptions to customize the transfer (including setting a final transform for the actor).

The documentation for this class was generated from the following file: