Page 1 of 1

UE4: Can't get NoesisInstance from blueprint

Posted: 06 Apr 2018, 12:55
by GeorgeR
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?

Re: UE4: Can't get NoesisInstance from blueprint

Posted: 06 Apr 2018, 21:05
by hcpizzi
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'"));

Re: UE4: Can't get NoesisInstance from blueprint

Posted: 07 Apr 2018, 01:27
by GeorgeR
This:
https://github.com/Noesis/UE4Plugin/blo ... tedClass.h

says it inherits from BlueprintGeneratedClass

Re: UE4: Can't get NoesisInstance from blueprint

Posted: 07 Apr 2018, 12:43
by hcpizzi
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.

Re: UE4: Can't get NoesisInstance from blueprint

Posted: 08 Apr 2018, 10:47
by GeorgeR
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.

Re: UE4: Can't get NoesisInstance from blueprint

Posted: 08 Apr 2018, 12:44
by hcpizzi
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?

Re: UE4: Can't get NoesisInstance from blueprint

Posted: 09 Apr 2018, 15:18
by GeorgeR
It looks like I had a pickled version of the plugin, or I needed to recompile it or something. Sorry for wasting your time.

Re: UE4: Can't get NoesisInstance from blueprint

Posted: 10 Apr 2018, 09:17
by hcpizzi
No worries. Glad you got it to work :)