Where is UUserWidget::OnLevelRemovedFromWorld in 5.1

UUserWidget::OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorld)

I tried to migrate from 5 to 5.1 and noticed this function has been removed.
any function that can replace it?

9 Likes

Im on the same boat, updating a plugin that worked with UE5, but needed this function.

I had same problem.
I am using
“virtual void NativeDestruct() override;”
instead of “virtual void NativeDestruct() override;” .

@poet are you saying you used NativeDestruct in place of OnLevelRemovedFromWorld? Or you’re just having the same issue with the NativeDestruct function?

NativeDestruct in place of OnLevelRemovedFromWorld.
UUserWidget does not have OnLevelRemovedFromWorld function anymore in UE5.1.
I would like to find Epic’s official saying to fix.
As for me, it works.

@poet okay thank you. For example, if OnLevelRemovedFromWorld is passed two params

(
  ULevel* InLevel,
  UWorld* InWorld
)

Does anything need to be passed into NativeDestruct or is this handled automatically? sorry, i’m new to UE and just trying to get a MultiplayerSessions plugin working properly with 5.1

Here’s the full file for reference.

MenuWidget.h

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "interfaces/OnlineSessionInterface.h"
#include "MenuWidget.generated.h"

/**
 * 
 */
UCLASS()
class MULTIPLAYERSESSIONS_API UMenuWidget : public UUserWidget
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintCallable)
	void MenuSetup(int32 NumberOfPublicConnections = 4, FString TypeOfMatch = FString(TEXT("FreeForAll")),FString LobbyPath = FString(TEXT("/Game/ThirdPerson/Maps/Lobby")));

protected:
	virtual bool Initialize() override;
	virtual void OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorld) override;

	// Callbacks for the custom delegates on the MultiplayerSessionsSubsystem
	UFUNCTION()
	void OnCreateSession(bool bWasSuccessful);
	void OnFindSession(const TArray<FOnlineSessionSearchResult>& SessionResults, bool bWasSuccessful);
	void OnJoinSession(EOnJoinSessionCompleteResult::Type Result);
	UFUNCTION()
	void OnDestroySession(bool bWasSuccessful);
	UFUNCTION()
	void OnStartSession(bool bWasSuccessful);
	
private:
	UPROPERTY(meta = (BindWidget))
	class UButton* HostButton;

	UPROPERTY(meta = (BindWidget))
	UButton* JoinButton;

	UFUNCTION()
	void HostButtonClicked();

	UFUNCTION()
	void JoinButtonClicked();

	void MenuTearDown();

	// The subsystem designed to handle all online session functionality
	class UMultiplayerSessionsSubsystem* MultiplayerSessionsSubsystem;

	int32 NumPublicConnections{4};
	FString MatchType{TEXT("FreeForAll")};
	FString PathToLobby{TEXT("")};
};

MenuWidget.cpp

void UMenuWidget::OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorld)
{
	MenuTearDown();
	Super::OnLevelRemovedFromWorld(InLevel, InWorld);
}

Github Repo: GitHub - gorojack/MultiplayerSessions: Unreal Engine MultiplayerSessions Plugin

UUserWidget::NativeDestruct().
It doesn’t take any parameters, but you’re not using the ones being passed into OnLevelRemovedFromWorld() anyways, so it should be fine.

7 Likes

Thank you so much. You not only helped me, but 10+ other people in this UE5 course i’m in as we’ve all been stuck on this. Much appreciated, I’ve been trying to figure this out for 3 days.

i’m also trouble with this problem and fortunately i found this post, i’m built with the same course and thank you all here.

we study the same class lol

Me too lol