# Where is UUserWidget::OnLevelRemovedFromWorld in 5.1

**URL:** <https://forums.unrealengine.com/t/where-is-uuserwidget-onlevelremovedfromworld-in-5-1/692215>\
**Category:** C++\
**Tags:** unreal-engine, UE5-1, Widget, question\
**Created:** [November 16, 2022, 6:19pm UTC](https://forums.unrealengine.com/t/where-is-uuserwidget-onlevelremovedfromworld-in-5-1/692215 "2022-11-16T18:19:07Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![AumieJaE](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AumieJaE](https://forums.unrealengine.com/u/AumieJaE)\
**Post date:** [November 16, 2022, 6:19pm UTC](https://forums.unrealengine.com/t/where-is-uuserwidget-onlevelremovedfromworld-in-5-1/692215/1 "2022-11-16T18:19:07Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![antara33](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@antara33](https://forums.unrealengine.com/u/antara33)\
**Post date:** [November 17, 2022, 5:45am UTC](https://forums.unrealengine.com/t/where-is-uuserwidget-onlevelremovedfromworld-in-5-1/692215/2 "2022-11-17T05:45:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![poet](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@poet](https://forums.unrealengine.com/u/poet)\
**Post date:** [November 19, 2022, 3:24am UTC](https://forums.unrealengine.com/t/where-is-uuserwidget-onlevelremovedfromworld-in-5-1/692215/3 "2022-11-19T03:24:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![agxra420](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@agxra420](https://forums.unrealengine.com/u/agxra420)\
**Post date:** [November 21, 2022, 8:06am UTC](https://forums.unrealengine.com/t/where-is-uuserwidget-onlevelremovedfromworld-in-5-1/692215/4 "2022-11-21T08:06:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![poet](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@poet](https://forums.unrealengine.com/u/poet)\
**Post date:** [November 21, 2022, 11:39am UTC](https://forums.unrealengine.com/t/where-is-uuserwidget-onlevelremovedfromworld-in-5-1/692215/6 "2022-11-21T11:39:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![agxra420](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@agxra420](https://forums.unrealengine.com/u/agxra420)\
**Post date:** [November 21, 2022, 7:28pm UTC](https://forums.unrealengine.com/t/where-is-uuserwidget-onlevelremovedfromworld-in-5-1/692215/7 "2022-11-21T19:28:40Z")

</div>

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

```auto
(
  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

```auto
#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

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

```

Github Repo: [GitHub - gorojack/MultiplayerSessions: Unreal Engine MultiplayerSessions Plugin](https://github.com/gorojack/MultiplayerSessions)

---

<div class="post-metadata">

**Author:** ![poet](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@poet](https://forums.unrealengine.com/u/poet)\
**Post date:** [November 22, 2022, 2:04am UTC](https://forums.unrealengine.com/t/where-is-uuserwidget-onlevelremovedfromworld-in-5-1/692215/8 "2022-11-22T02:04:59Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![agxra420](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@agxra420](https://forums.unrealengine.com/u/agxra420)\
**Post date:** [November 22, 2022, 7:01am UTC](https://forums.unrealengine.com/t/where-is-uuserwidget-onlevelremovedfromworld-in-5-1/692215/9 "2022-11-22T07:01:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Bilibili\_Back](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Bilibili\_Back](https://forums.unrealengine.com/u/Bilibili_Back)\
**Post date:** [November 22, 2022, 8:03am UTC](https://forums.unrealengine.com/t/where-is-uuserwidget-onlevelremovedfromworld-in-5-1/692215/10 "2022-11-22T08:03:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![123274281](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/123274281/32/917886_2.png) [@123274281](https://forums.unrealengine.com/u/123274281)\
**Post date:** [January 30, 2023, 8:08am UTC](https://forums.unrealengine.com/t/where-is-uuserwidget-onlevelremovedfromworld-in-5-1/692215/11 "2023-01-30T08:08:24Z")

</div>

we study the same class lol

---

<div class="post-metadata">

**Author:** ![JungerSoda](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JungerSoda](https://forums.unrealengine.com/u/JungerSoda)\
**Post date:** [March 3, 2023, 8:35am UTC](https://forums.unrealengine.com/t/where-is-uuserwidget-onlevelremovedfromworld-in-5-1/692215/12 "2023-03-03T08:35:46Z")

</div>

Me too lol
