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

The subsystem of the MultiWorld plugin. More...

#include <MultiWorldManager.h>

Inheritance diagram for UMultiWorldManager:

Public Member Functions

 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam (FOnPreEndWorld, FMultiWorldHandle, WorldToEnd)
 FOnPreEndWorld delegate signature. More...
 
 DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams (FOnWorldSwitched, FMultiWorldHandle, PreviousWorld, FMultiWorldHandle, CurrentWorld)
 FOnWorldSwitched delegate signature. More...
 
virtual void Deinitialize () override
 Override USubsystem::Deinitialize. More...
 
void EndAllWorlds (TFunction< void()> OnCompleteCallback)
 
void EndWorld (const FMultiWorldHandle &InWorldHandle, TFunction< void()> OnCompleteCallback)
 Deprecated version of EndWorld. More...
 
void FixUpLocalPlayers ()
 Check local player setup and fixup if it's invalid. More...
 
void ForEachSecondaryWorld (TFunction< void(UWorld *)> Predicate)
 Utility to "visit" all loaded worlds. More...
 
FMultiWorldHandle GetActiveWorldHandle () const
 Return the world handle of the active World. More...
 
FMultiWorldHandle GetMainWorldHandle () const
 Return the main world handle. More...
 
virtual TStatId GetStatId () const override
 Override. More...
 
FMultiWorldHandle GetThisWorldHandle (const UObject *WorldContextObject) const
 Return the world handle where the caller lives. More...
 
FMultiWorldHandle GetWorldHandleByName (FName WorldName) const
 Return the world handle of the world with the given name if found or an invalid handle otherwise. More...
 
virtual void Initialize (FSubsystemCollectionBase &Collection) override
 Override USubsystem::Initialize. More...
 
void InitializeWorld (const FMultiWorldHandle &InWorldHandle)
 Setup the input World for playing; Actors are intialized, BeginPlay is called etc... After you call this method, the world is ready for playing and you can switch world calling SwitchWorld. More...
 
virtual bool IsTickable () const override
 Override. More...
 
bool IsValidHandle (const FMultiWorldHandle &InWorldHandle) const
 Return true if the input world handle is valid, false otherwise. More...
 
void LoadWorld (TSoftObjectPtr< UWorld > MapAsset, FMultiWorldLoadParameters InParams, TFunction< void(bool, FMultiWorldHandle, FMultiWorldLoadParameters)> OnCompleteCallback)
 Synchronously load a World into memory. More...
 
void LoadWorldAsync (TSoftObjectPtr< UWorld > MapAsset, FMultiWorldLoadParameters InParams, TFunction< void(bool, FMultiWorldHandle, FMultiWorldLoadParameters)> OnCompleteCallback)
 Asynchronously load a World into memory. More...
 
void RequestSwitchWorld (const FMultiWorldHandle &InWorldHandle, TFunction< void(bool)> OnSwitchWorldCompleted)
 Like SwitchWorld() but the switch will take place in the next frame and outside the worlds ticking. More...
 
bool ReturnToMainWorld ()
 Travel the local players to the main world. More...
 
void SetAutoHandleInputModeForMainWorld (bool bAutoHandleWidgets)
 Sets whenever the InputMode must be handled and restored for the main world automatically. More...
 
void SetAutoHandleWidgetsForMainWorld (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...
 
void SetShouldTickWhenInBackground (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...
 
AActor * SpawnActorInWorld (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...
 
bool SwitchWorld (const FMultiWorldHandle &InWorldHandle)
 Change the Active World, travelling the local players to the input world. More...
 
virtual void Tick (float DeltaTime) override
 Override. More...
 
void TransferActorToWorld (AActor *InActor, const FMultiWorldHandle &InWorldHandle, const FMultiWorldTransferActorParameters &Options)
 Transfer the input actor from its actual world to the input one. More...
 

Static Public Member Functions

static UMultiWorldManagerGetInstance (const UObject *context)
 Return the multi world manager instance. More...
 

Public Attributes

FOnLoadWorldCompletedDelegate OnLoadWorldCompleted
 Delegate called when the world load has terminated. More...
 
FOnPreEndWorld OnPreWorldEnded
 Delegate called before the world is ended. More...
 
FOnWorldSwitched OnWorldSwitched
 Delegate called when the world is switched. More...
 

Friends

class UMultiWorldOverrides
 

Detailed Description

The subsystem of the MultiWorld plugin.

Member Function Documentation

◆ DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam()

UMultiWorldManager::DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam ( FOnPreEndWorld  ,
FMultiWorldHandle  ,
WorldToEnd   
)

FOnPreEndWorld delegate signature.

◆ DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams()

UMultiWorldManager::DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams ( FOnWorldSwitched  ,
FMultiWorldHandle  ,
PreviousWorld  ,
FMultiWorldHandle  ,
CurrentWorld   
)

FOnWorldSwitched delegate signature.

◆ Deinitialize()

virtual void UMultiWorldManager::Deinitialize ( )
overridevirtual

Override USubsystem::Deinitialize.

◆ EndAllWorlds()

void UMultiWorldManager::EndAllWorlds ( TFunction< void()>  OnCompleteCallback)

◆ EndWorld()

void UMultiWorldManager::EndWorld ( const FMultiWorldHandle InWorldHandle,
TFunction< void()>  OnCompleteCallback 
)

Deprecated version of EndWorld.

See also
EndWorldWithDelegate

◆ FixUpLocalPlayers()

void UMultiWorldManager::FixUpLocalPlayers ( )

Check local player setup and fixup if it's invalid.

It must be invoked by UGameViewportClient::LayoutPlayers

◆ ForEachSecondaryWorld()

void UMultiWorldManager::ForEachSecondaryWorld ( TFunction< void(UWorld *)>  Predicate)
inline

Utility to "visit" all loaded worlds.

The predicate function is called for each loaded world.

◆ GetActiveWorldHandle()

FMultiWorldHandle UMultiWorldManager::GetActiveWorldHandle ( ) const

Return the world handle of the active World.

Parameters
[in]WorldContextObjectthe world context object

◆ GetInstance()

static UMultiWorldManager & UMultiWorldManager::GetInstance ( const UObject *  context)
static

Return the multi world manager instance.

◆ GetMainWorldHandle()

FMultiWorldHandle UMultiWorldManager::GetMainWorldHandle ( ) const
inline

Return the main world handle.

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

Parameters
[in]WorldContextObjectthe world context object

◆ GetStatId()

virtual TStatId UMultiWorldManager::GetStatId ( ) const
overridevirtual

Override.

◆ GetThisWorldHandle()

FMultiWorldHandle UMultiWorldManager::GetThisWorldHandle ( const UObject *  WorldContextObject) const

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()

FMultiWorldHandle UMultiWorldManager::GetWorldHandleByName ( FName  WorldName) const

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

◆ Initialize()

virtual void UMultiWorldManager::Initialize ( FSubsystemCollectionBase &  Collection)
overridevirtual

Override USubsystem::Initialize.

◆ InitializeWorld()

void UMultiWorldManager::InitializeWorld ( const FMultiWorldHandle InWorldHandle)

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

Attention
it's not necessary to call this function if the world was loaded with the setting 'bAutoInitializeWorld' set to true.
Parameters
[in]WorldContextObjectthe world context object
InWorldHandlethe world to setup; it should came from the function LoadWorld.

◆ IsTickable()

virtual bool UMultiWorldManager::IsTickable ( ) const
overridevirtual

Override.

◆ IsValidHandle()

bool UMultiWorldManager::IsValidHandle ( const FMultiWorldHandle InWorldHandle) const

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

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

◆ LoadWorld()

void UMultiWorldManager::LoadWorld ( TSoftObjectPtr< UWorld >  MapAsset,
FMultiWorldLoadParameters  InParams,
TFunction< void(bool, FMultiWorldHandle, FMultiWorldLoadParameters)>  OnCompleteCallback 
)

Synchronously load a World into memory.

This method works like UMultiWorldStatics::LoadWorldWithDelegate(), but uses a C++ completion callback instead of a delegate.

◆ LoadWorldAsync()

void UMultiWorldManager::LoadWorldAsync ( TSoftObjectPtr< UWorld >  MapAsset,
FMultiWorldLoadParameters  InParams,
TFunction< void(bool, FMultiWorldHandle, FMultiWorldLoadParameters)>  OnCompleteCallback 
)

Asynchronously load a World into memory.

This method works like UMultiWorldStatics::LoadWorldAsyncWithDelegate(), but uses a C++ completion callback instead of a delegate.

◆ RequestSwitchWorld()

void UMultiWorldManager::RequestSwitchWorld ( const FMultiWorldHandle InWorldHandle,
TFunction< void(bool)>  OnSwitchWorldCompleted 
)

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

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

◆ ReturnToMainWorld()

bool UMultiWorldManager::ReturnToMainWorld ( )

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

◆ SetAutoHandleInputModeForMainWorld()

void UMultiWorldManager::SetAutoHandleInputModeForMainWorld ( bool  bAutoHandleWidgets)

Sets whenever the InputMode must be handled and restored for the main world automatically.

True by default. In Unreal Engine the Input Mode is defined globally and so "leaks" between worlds. If AutoHandleInputMode is true, the plugin save the actual input mode when we leave the world and restore it when we return back to that world.

Parameters
[in]WorldContextObjectthe world context object
[in]bAutoHandleInputModetrue if the input mode is handled automatically for the main world, false otherwise.

◆ SetAutoHandleWidgetsForMainWorld()

void UMultiWorldManager::SetAutoHandleWidgetsForMainWorld ( 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).

True by default.

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

◆ SetShouldTickWhenInBackground()

void UMultiWorldManager::SetShouldTickWhenInBackground ( 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).

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()

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

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()

bool UMultiWorldManager::SwitchWorld ( const FMultiWorldHandle InWorldHandle)

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()). Player controllers input mode is managed accordingly to the configuration (see FMultiWorldLoadParameters::bAutoHandleInputMode and UMultiWorldStatics::SetAutoHandleInputModeForMainWorld()).

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

◆ Tick()

virtual void UMultiWorldManager::Tick ( float  DeltaTime)
overridevirtual

Override.

◆ TransferActorToWorld()

void UMultiWorldManager::TransferActorToWorld ( AActor *  InActor,
const FMultiWorldHandle InWorldHandle,
const FMultiWorldTransferActorParameters Options 
)

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).

Member Data Documentation

◆ OnLoadWorldCompleted

FOnLoadWorldCompletedDelegate UMultiWorldManager::OnLoadWorldCompleted

Delegate called when the world load has terminated.

◆ OnPreWorldEnded

FOnPreEndWorld UMultiWorldManager::OnPreWorldEnded

Delegate called before the world is ended.

◆ OnWorldSwitched

FOnWorldSwitched UMultiWorldManager::OnWorldSwitched

Delegate called when the world is switched.


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