[Question] Create Widget from UManagerClass


i am having some troubles to use the Node “Create Widget” within my custom UManagerClass Blueprint (aka UI Manager). It derives from UObject
and is instantiated in my custom GameInstance Class.

He always tells me this:
" Warning Function ’ Create Widget ’ is unsafe to call from blueprints of class ’ UserInterfaceManager '."
" Error Pin World Context Object must have a connection"

I have the following includes i thought i would need but the problem still perists:

#include "UserWidget.h"
#include "Runtime/UMG/Public/UMG.h"
#include "SlateBasics.h"
#include "../UI/MyUserWidget.h"
#include "UserInterfaceManager.generated.h"

Someone knows what i am missing?

when i call CreateWidget within c++ of the parent class its all fine. But this would need me to create a new Function which is able to return my custom
Widgets i dont think this would be needed, since “CreateWidget” already do everything i need.

best regards

Creating widgets need a world context object in order to access the game instance that owns the world. So your UserInterfaceManager needs to implement GetWorld(), and return the active world belonging to your owner game instance.

thanks for your reply, that helped a lot :slight_smile:

Exactly what I needed, thanks a lot!

How to implement GetWorld, like this ?

UWorld* UEditorTutorial::GetWorld() const
if (GIsEditor)
return GWorld;
#endif // WITH_EDITOR
return GEngine->GetWorldContexts()[0].World();