GeorgeR
Topic Author
Posts: 39
Joined: 15 Mar 2018, 01:06

UE4: Can't get NoesisInstance from blueprint

06 Apr 2018, 12:55

I'm creating my UI stuff in code, and I usually do something like this to get my widget class:
const auto WidgetClass = LoadClass<UUserWidget>(this, TEXT("UserWidget'/Game/Frontier/UI/WBP_Something.WBP_Something_C'"));
(where _C is the generated class, the blueprint is excluded from the packaged build), and it correctly loads as a UUserWidget, however when I loaded a NoesisInstance like this:
const auto WidgetClass = LoadClass<UNoesisInstance>(this, TEXT("NoesisInstance'/Game/Frontier/UI/WBP_Something.WBP_Something_C'"));
The returned class is a UNoesisBlueprintGeneratedClass, and I can't cast it to a UNoesisInstance. This means CreateWidget is fed a non-UUserWidget class and fails.

How do I get a UNoesisInstance from the generated class?
 
User avatar
hcpizzi
Site Admin
Posts: 325
Joined: 09 Feb 2012, 12:40

Re: UE4: Can't get NoesisInstance from blueprint

06 Apr 2018, 21:05

I tested this code and it works for me:
const auto WidgetClass = LoadClass<UNoesisInstance>(nullptr, TEXT("NoesisInstance'/Game/NewNoesisBlueprint.NewNoesisBlueprint_C'"));
UUserWidget* Widget = CreateWidget<UUserWidget>(GetWorld(), WidgetClass);
Widget->AddToViewport();
UNoesisBlueprintGeneratedClass inherits from UNoesisInstance, which in turn inherits from UUserWidget, so even this works:
const auto WidgetClass = LoadClass<UUserWidget>(nullptr, TEXT("NoesisInstance'/Game/NewNoesisBlueprint.NewNoesisBlueprint_C'"));
 
GeorgeR
Topic Author
Posts: 39
Joined: 15 Mar 2018, 01:06

Re: UE4: Can't get NoesisInstance from blueprint

07 Apr 2018, 01:27

This:
https://github.com/Noesis/UE4Plugin/blo ... tedClass.h

says it inherits from BlueprintGeneratedClass
 
User avatar
hcpizzi
Site Admin
Posts: 325
Joined: 09 Feb 2012, 12:40

Re: UE4: Can't get NoesisInstance from blueprint

07 Apr 2018, 12:43

You're right, I didn't express myself correctly.

/Game/Frontier/UI/WBP_Something.WBP_Something_C is an instance of UNoesisBlueprintGeneratedClass that contains the reflection information that describes the class resulting from compiling /Game/Frontier/UI/WBP_Something.WBP_Something. If you look at it with the debugger, you'll see that it has a member called SuperStruct, inherited from UStruct, that points to the UClass that describes UNoesisInstance. If you again look at the SuperStruct member of that UClass you'll see that it points to the UClass that describes UUserWidget. But those are native classes, so you can figure that out by looking at the code. That's what I meant when I said that UNoesisBlueprintGeneratedClass inherits from UNoesisInstance, which in turn inherits from UUserWidget. What I really should have said is that that instance of a UNoesisBlueprintGeneratedClass represents a class that inherits from UNoesisInstance, which in turn inherits from UUserWidget

If you do the same thing with the WidgetBlueprint class, you'll see that /Game/Frontier/UI/WBP_Something.WBP_Something_C is an instance of UWidgetBlueprintGeneratedClass, and its SuperStruct member points to thesame UClass describing UUserWidget as the UClass describing UNoesisInstance does.
 
GeorgeR
Topic Author
Posts: 39
Joined: 15 Mar 2018, 01:06

Re: UE4: Can't get NoesisInstance from blueprint

08 Apr 2018, 10:47

I tested this code and it works for me:
const auto WidgetClass = LoadClass<UNoesisInstance>(nullptr, TEXT("NoesisInstance'/Game/NewNoesisBlueprint.NewNoesisBlueprint_C'"));
UUserWidget* Widget = CreateWidget<UUserWidget>(GetWorld(), WidgetClass);
Widget->AddToViewport();
I tested that exact code but with my class and it didn't work. WidgetClass is ok but Widget is null.
 
User avatar
hcpizzi
Site Admin
Posts: 325
Joined: 09 Feb 2012, 12:40

Re: UE4: Can't get NoesisInstance from blueprint

08 Apr 2018, 12:44

Have you tried stepping through UUserWidget::CreateWidgetOfClass? Is GetWorld() returning null? Or does it fail in CreateWidgetHelpers::ValidateUserWidgetClass? Regardless, I think all failure paths in that function write to the message log. Do you get an error when you run it?
 
GeorgeR
Topic Author
Posts: 39
Joined: 15 Mar 2018, 01:06

Re: UE4: Can't get NoesisInstance from blueprint

09 Apr 2018, 15:18

It looks like I had a pickled version of the plugin, or I needed to recompile it or something. Sorry for wasting your time.
 
User avatar
hcpizzi
Site Admin
Posts: 325
Joined: 09 Feb 2012, 12:40

Re: UE4: Can't get NoesisInstance from blueprint

10 Apr 2018, 09:17

No worries. Glad you got it to work :)

Who is online

Users browsing this forum: Bing [Bot] and 4 guests