MultiWorld 1.5.0
Manage multiple isolated UWorld instances simultaneously in Unreal Engine, transferring player and actors between worlds.
Loading...
Searching...
No Matches
GetPlayerController in UE5

GetPlayerController in UE5

The behavior of UGameplayStatics::GetPlayerController() changed in UE5, compared to UE4.

The UE4 implementation is using the contextual UWorld instance when looking for the UPlayerController. The UE5 implementation relies on other information, sometimes un-related to the contextual UWorld instance, to retrieve the UPlayerController; this can cause the wrong UPlayerController object to be returned.

To workaround this type of issues, the method UMultiWorldStatics::GetPlayerController() is provided by the plugin.

Issues in UE5.0.2+

The implementation available starting from UE5.0.2, while correctly retrieving the right contextual UWorld instance, still relies on the ULocalPlayer of the UGameInstance singleton; in some contexts, the returned UPlayerController is wrong. In particular with delegates, when the associated code is bound to a particular UWorld instance A, but the delegate is notified by a different UWorld instance B.

To workaround this type of issues, the provided method UMultiWorldStatics::GetPlayerController() can be used.

Bug in UE5.0.0-UE5.0.1

This issue has been solved by Epic in UE5.0.2: https://github.com/EpicGames/UnrealEngine/commit/b1a0a5fb064d25af679c78a234e1f85471902a98. Notes below apply only to UE5.0.0 and UE5.0.1.

UE5.0.0 introduced a bug in the implementation of UGameplayStatics::GetPlayerController(), that no longer returns the correct UWorld instance from the passed World Context Object (it always returns the Active World instead). This applies only to UE5, not to UE4. Since this method is often used in Blueprints and C++, knowing the available workarounds is important.

Until Epic will solve this issue, in UE5 you MUST work-around this bug retrieving the Player Controller of a desired UWorld calling the method UGameplayStatics::GetPlayerState() and, on the returned Player State object, the method APlayerState::GetPlayerController().

The same issue applies also to the methods UGameplayStatics::GetPlayerPawn(), UGameplayStatics::GetPlayerCharacter(), UGameplayStatics::GetPlayerCameraManager(); and the same workaround MUST be used (i.e. retrieving the desired objects passing from UGameplayStatics::GetPlayerState()).

If you are working directly with the engine source code, alternatively you can back-out (part of) the linked changeset restoring the same behavior as in UE4. Of course this will remove also the fix provided by that commit, so analyze it carefully before proceeding with this option.