# How do you convert a UUserWidget to a SWidget? Needed for a loadingscreen.

**URL:** <https://forums.unrealengine.com/t/how-do-you-convert-a-uuserwidget-to-a-swidget-needed-for-a-loadingscreen/343494>\
**Category:** UI\
**Tags:** convert, unreal-engine, loading-screen, Widget, CPP, question\
**Created:** [January 8, 2016, 4:45pm UTC](https://forums.unrealengine.com/t/how-do-you-convert-a-uuserwidget-to-a-swidget-needed-for-a-loadingscreen/343494 "2016-01-08T16:45:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_d71a2fac1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d71a2fac1](https://forums.unrealengine.com/u/anonymous_user_d71a2fac1)\
**Post date:** [January 8, 2016, 4:45pm UTC](https://forums.unrealengine.com/t/how-do-you-convert-a-uuserwidget-to-a-swidget-needed-for-a-loadingscreen/343494/1 "2016-01-08T16:45:10Z")

</div>

Hey, i have been working on getting a loading screen for my game and have gotten the basic loading screen working by using this.

```
void UHomeInvasionGameInstance::Init()
{
	UGameInstance::Init();

	FCoreUObjectDelegates::PreLoadMap.AddUObject(this, &UHomeInvasionGameInstance::BeginLoadingScreen);
	FCoreUObjectDelegates::PostLoadMap.AddUObject(this, &UHomeInvasionGameInstance::EndLoadingScreen);
}

void UHomeInvasionGameInstance::BeginLoadingScreen()
{
	FLoadingScreenAttributes LoadingScreen;
	LoadingScreen.bAutoCompleteWhenLoadingCompletes = false;
	LoadingScreen.MinimumLoadingScreenDisplayTime = MinLoadTime;
	LoadingScreen.WidgetLoadingScreen = FLoadingScreenAttributes::NewTestLoadingScreenWidget();

	GetMoviePlayer()->SetupLoadingScreen(LoadingScreen);
}

void UHomeInvasionGameInstance::EndLoadingScreen()
{

}

```

But i have gotten a bit confused on how you would go about setting your own custom widget to display when loading the maps. I understand that it is this variable that should be set to the wanted widget, but i don’t really understand how i would convert a UserWidget that i have created to a SWidget.

```
	/** The widget to be displayed on top of the movie or simply standalone if there is no movie. */
	TSharedPtr<class SWidget> WidgetLoadingScreen;

```

Some help would be appreciated.

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [January 8, 2016, 5:32pm UTC](https://forums.unrealengine.com/t/how-do-you-convert-a-uuserwidget-to-a-swidget-needed-for-a-loadingscreen/343494/2 "2016-01-08T17:32:21Z")

</div>

So let me say this about UMG and Slate, UMG is UObject-compatible frontend of Slate, created to make Slate usable in blueprints (as all Slate classes are non-UObject and invisible to reflection system there for can’t be used in blueprints) and all UMG widgets (with prefix U) are containers for Slate widgets (with S prefix). So slate practiclly have same widgets… even more widgets them UMG has

To get underling SWidget of UMG widget you use this function:

> **[UWidget::TakeWidget](https://docs.unrealengine.com/5.1/en-US/API/Runtime/UMG/Components/UWidget/TakeWidget/)**
>
> Gets the underlying slate widget or constructs it if it doesn't exist.

Also alternatively you can easily construct Slate widgets, it really super easy which makes Slate very easy to use in C++, here examples:

> **[Slate Widget Examples](https://docs.unrealengine.com/5.1/en-US/slate-ui-widget-examples-for-unreal-engine/)**
>
> Layout and widget complexities not demonstrated in the Slate Viewer Widget Gallery.

But i understand you want to use UMG editor to declere Slate widgets insted ;]

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_d71a2fac1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d71a2fac1](https://forums.unrealengine.com/u/anonymous_user_d71a2fac1)\
**Post date:** [January 8, 2016, 8:26pm UTC](https://forums.unrealengine.com/t/how-do-you-convert-a-uuserwidget-to-a-swidget-needed-for-a-loadingscreen/343494/3 "2016-01-08T20:26:01Z")

</div>

That is perfect, works just like i want it. Thanks!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1e40b7c0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1e40b7c0](https://forums.unrealengine.com/u/anonymous_user_1e40b7c0)\
**Post date:** [January 12, 2016, 12:01am UTC](https://forums.unrealengine.com/t/how-do-you-convert-a-uuserwidget-to-a-swidget-needed-for-a-loadingscreen/343494/4 "2016-01-12T00:01:45Z")

</div>

I don’t mean to hijack the post, but I figured that I would be able to get get some pointers on getting my loading screen setup as you two seem to have it figured out.

Below are screens of my header and cpp file, but there seem to be some errors that I’m running into.

[http://puu.sh/mskXm/3c72dbe928.png](http://puu.sh/mskXm/3c72dbe928.png)

[http://puu.sh/mskZx/1e9cac8623.png](http://puu.sh/mskZx/1e9cac8623.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_d71a2fac1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d71a2fac1](https://forums.unrealengine.com/u/anonymous_user_d71a2fac1)\
**Post date:** [January 12, 2016, 8:08am UTC](https://forums.unrealengine.com/t/how-do-you-convert-a-uuserwidget-to-a-swidget-needed-for-a-loadingscreen/343494/5 "2016-01-12T08:08:33Z")

</div>

What errors are you getting?  
Also, have you included the “MoviePlayer” module in build.CS file?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1e40b7c0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1e40b7c0](https://forums.unrealengine.com/u/anonymous_user_1e40b7c0)\
**Post date:** [January 12, 2016, 6:08pm UTC](https://forums.unrealengine.com/t/how-do-you-convert-a-uuserwidget-to-a-swidget-needed-for-a-loadingscreen/343494/6 "2016-01-12T18:08:19Z")

</div>

Yes I added MoviePlayer into my LostEchoes.Build.cs file.  
My errors are pretty funky like “missing ;” but my whole game compiles and runs fine. Just that the red underlines never go away, and I don’t seem to have a load screen running when I start my game.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1e40b7c0](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1e40b7c0](https://forums.unrealengine.com/u/anonymous_user_1e40b7c0)\
**Post date:** [January 12, 2016, 6:27pm UTC](https://forums.unrealengine.com/t/how-do-you-convert-a-uuserwidget-to-a-swidget-needed-for-a-loadingscreen/343494/7 "2016-01-12T18:27:16Z")

</div>

Oh, looks like errors have left after a full clean and rebuild. Sorry and thanks!

---

<div class="post-metadata">

**Author:** ![alsanoja](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@alsanoja](https://forums.unrealengine.com/u/alsanoja)\
**Post date:** [July 31, 2017, 10:28pm UTC](https://forums.unrealengine.com/t/how-do-you-convert-a-uuserwidget-to-a-swidget-needed-for-a-loadingscreen/343494/8 "2017-07-31T22:28:30Z")

</div>

I’m curious what you did to get it working with your UMG widgets. I attempted to essentially get a UUserWidget to the SWidget needed and when debugging it has a valid object. However I then receive a Rendering Thread exception. It works with the base load screen from FLoadingScreenAttributes::NewTestLoadingScreenWidget(). The relevant part of my Game instance is below. the wLoading essentially is where the LoadingWidget is set and then it constantly gets casted or built into an SWidget to be placed inside the movie player loading screen.

```
  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Widgets")
    TSubclassOf<class UUserWidget> wLoading;

  UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Widgets")
  UUserWidget* LoadingWidget;

private:
  TSharedPtr < class SWidget > loadswidget;

void UCustomGameInstance::Init()
{
  UGameInstance::Init();

  FCoreUObjectDelegates::PreLoadMap.AddUObject(this, &UCustomGameInstance::BeginLoadingScreen);

  FCoreUObjectDelegates::PostLoadMap.AddUObject(this, &UCustomGameInstance::EndLoadingScreen);

  LoadingWidget = CreateWidget(this, wLoading);
  loadswidget = LoadingWidget->TakeWidget();
}

void UCustomGameInstance::BeginLoadingScreen(const FString& MapName)
{
    FLoadingScreenAttributes LoadingScreen;

    LoadingScreen.bAutoCompleteWhenLoadingCompletes = true;
    LoadingScreen.WidgetLoadingScreen = loadswidget;

    GetMoviePlayer()->SetupLoadingScreen(LoadingScreen);

}

```

---

<div class="post-metadata">

**Author:** ![RHZhang](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RHZhang](https://forums.unrealengine.com/u/RHZhang)\
**Post date:** [December 11, 2017, 8:54am UTC](https://forums.unrealengine.com/t/how-do-you-convert-a-uuserwidget-to-a-swidget-needed-for-a-loadingscreen/343494/9 "2017-12-11T08:54:43Z")

</div>

Hello, thanks in advance for your code.  
I referred to it, and I also met a rendering exception, not sure whether the same as you met, when I load map for the second time.

I also found `LoadingWidget` became unusable for the second time as I play in viewport, and that widget is destroyed on loading map.

Then I put `LoadingWidget = CreateWidget(this, wLoading);` in `BeginLoadingScreen`, and no crash occurs either in PlayInViewport or in Standalone. It works.

PS. My MoviePlayer only works in Standalone (screen stuck in PlayInViewport until map is loaded). Are yours the same?

---

<div class="post-metadata">

**Author:** ![FergiusTerro](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/fergiusterro/32/1020723_2.png) [@FergiusTerro](https://forums.unrealengine.com/u/FergiusTerro)\
**Post date:** [November 6, 2024, 5:16pm UTC](https://forums.unrealengine.com/t/how-do-you-convert-a-uuserwidget-to-a-swidget-needed-for-a-loadingscreen/343494/10 "2024-11-06T17:16:40Z")

</div>

We’ve put together a comprehensive guide on using UMG within Slate—find it [here](https://dev.epicgames.com/community/learning/tutorials/dB67/unreal-engine-fab-integrating-umg-in-the-unreal-editor-with-slate-framework-a-practical-guide-and-case-study).
