Announcement

Collapse
No announcement yet.

Setup My BP Widget to WidgetComponent in AActor via C++

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

  • replied
    Originally posted by BrUnO XaVIeR View Post
    Btw... If you really need that to run in Constructor, first make sure this isn't a native class constructor running:

    Code:
    if ( HasAnyFlags( RF_Archetype | RF_DefaultObject ) )
    return;
    
    // then load widget here...
    That should stop your Editor from crashing at startup at least.
    Thanks a lot and big ship with a small cart=))

    I tried to move setWidgetClass() into BeginPlay(), and its works fine.
    So I decided it normal way to my score =)

    Thanks a lot again =)

    Leave a comment:


  • replied
    Btw... If you really need that to run in Constructor, first make sure this isn't a native class constructor running:

    Code:
    if ( HasAnyFlags( RF_Archetype | RF_DefaultObject ) )
        return;
    
    // then load widget here...
    That should stop your Editor from crashing at startup at least.

    Leave a comment:


  • replied
    Originally posted by BrUnO XaVIeR View Post
    Why do you need it to be in a datatable?
    I have more then 16 blueprint classes, that inhert from C++ class.
    So I want to create once WidgetComponent and set once MyWidget. And now its dont want to work =)
    And, I don't try yet set Widget in BeginPlay. And I think - its way too.

    If I want to use TSubclassOf in C++ class then I need set MyWidget in all my 16 BPClasses widget manually.
    Its not so cool =) If I will want to create another 16 BP classes? I must to remember, that I must set widgets in all new BP manually? =(((

    Leave a comment:


  • replied
    Why do you need it to be in a datatable?
    You can add TSubclassOf<UUserWidget> directly to the Component.

    Also, if you're using it in Constructor, your code will run while Editor is loading and your BP_Widget class didn't load yet... then crash.

    You don't need to call SetWidgetClass() in the Constructor. You can do that in BeginPlay for example.

    Leave a comment:


  • Setup My BP Widget to WidgetComponent in AActor via C++

    Hi. Sorry for my bad English.

    I have problem.
    When I try to load my BP widget via WidgetComponent in AMyActor, I have some strange behavior. Its work for started Editor. Compile successful, no errors, all works fine.
    BUT.
    If I close Editor and start it again - Editor will failed to load with error - cannot find BP Widget.

    How it happens:

    I have AActor Object with WidgetComponent;

    1. I created struct FWidgetRef form FTableRowBase;
    2. In struct I added TSubclassOf<UUserWidget> MenuWidget;
    3. I created BP MyWidget with some buttons;
    4. I created MyDataTable via Blueprint;
    5. I set link to MyWidget in MyDataTable.

    6. I get *FWidgetRef = MyDataTable->FindRow<FWidgetRef>( FName( "NewRow" ), FString( "Cannot find DataTable with Widget via DT->FindRow" ), true );
    7. WidgetComponent->SetWidgetClass(FWidgetRef->MenuWidget);

    So. It is work. When Editor is open. But, If I close it, rhen try to open - Editor every time crash with error.

    What do I wrong?
    How must I to do?
    Last edited by DenKuzn; 05-18-2019, 08:26 AM.
Working...
X