Announcement

Collapse
No announcement yet.

Use FObjectFinder with TSubClassof variable?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • replied
    Yeah, searching directly for the UClass like that will work. The only drawback is that you're then relying on the assumption that the name of a blueprint generated class is the same as the name of the blueprint asset with "_C" appended. It's unlikely Epic would change this, but it's not guaranteed. There's also the (again very unlikely) possibility that this might fail in the case of a naming conflict.

    Leave a comment:


  • replied
    When I tried to use UMG in C++ I could make it work loading its class inside constructor this way:

    Code:
    static ConstructorHelpers::FObjectFinder<UClass> ErrWdgtCntnt(TEXT("/Game/UI/Widgets/Common/WGT_Warning.WGT_Warning_C"));
    ErrorDialogWidget = ErrWdgtCntnt.Object;
    and this way outside constructor:

    Code:
    ErrorDialogWidget = StaticLoadClass(UObject::StaticClass(), nullptr, TEXT("/Game/UI/Widgets/Common/WGT_Warning.WGT_Warning_C"));
    UUserWidget * HUD = CreateWidget<UUserWidget>(GetWorld(), ErrorDialogWidget);
    Cheers
    Last edited by danielvmacedo; 08-05-2015, 01:26 AM.

    Leave a comment:


  • replied
    Yeah my fault, I ended up using UClass instead which seemed to work, though I feel like I should be casting it that way...

    Also had to add _C to the reference... for some reason. I'll try your version... that'd make more sense. Thanks!

    Leave a comment:


  • replied
    So basically what you're doing there (if you remove the *) is looking for an actual asset of type UUserWidget. Those don't exist, you have a widget blueprint asset, which has an associated class which is what you're after. I don't have time to test it out now, but something like this might do it:

    Code:
    static ConstructorHelpers::FObjectFinder<UWidgetBlueprint> ErrWdgtCntnt(TEXT("WidgetBlueprint'/Game/UI/Widgets/Common/WGT_Warning.WGT_Warning'"));
    if (ErrWdgtCntnt.Object != nullptr)
    {
      ErrorDialogWidget = ErrWdgtCntnt.Object->GeneratedClass;
    }

    Leave a comment:


  • replied
    You shouldn't have a * on the end of your FObjectFinder template argument. Otherwise should work fine.

    Edit: actually there's an instance/class issue here, need to think a bit more...

    Leave a comment:


  • started a topic Use FObjectFinder with TSubClassof variable?

    Use FObjectFinder with TSubClassof variable?

    Is it possible to use the TSubclassof container with FObjectFinder? I basically want to set the default property of a TSubclassof<UUserWidget> The following doesn't compile:

    Code:
    	static ConstructorHelpers::FObjectFinder<UUserWidget*> ErrWdgtCntnt(TEXT("WidgetBlueprint'/Game/UI/Widgets/Common/WGT_Warning.WGT_Warning'"));
    	if (ErrWdgtCntnt.Object != nullptr) { ErrorDialogWidget = (ErrWdgtCntnt.Object); }
Working...
X