Announcement

Collapse
No announcement yet.

C++ Widget

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

  • replied
    The error was because i missed to include USGameplayWidget.h and only added the forward declaration of the class

    Leave a comment:


  • replied
    i have a problem trying to create a custom widget.
    i have this code.
    Code:
    static ConstructorHelpers::FClassFinder<UUserWidget> MenuClassFinder(TEXT("/Game/Blueprints/UI/WBP_Gameplay"));
    
        if(!MenuClassFinder.Succeeded())
        {
            UE_LOG(LogTemp, Error, TEXT(" USGameplayWidget !UITmp.Succeeded() "));
            return;
        }
    
        TSubclassOf<class UUserWidget> MenuClass = MenuClassFinder.Class;
    
    
        USGameplayWidget* Menu = CreateWidget<USGameplayWidget>(this, MenuClass);
    but i get the error
    Code:
    Severity    Code    Description    Project    File    Line    Suppression State
    Error    C2338    CreateWidget can only be used to create UserWidget instances. If creating a UWidget, use WidgetTree::ConstructWidget.    CastleVersus    C:\Program Files\Epic Games\UE_4.23\Engine\Source\Runtime\UMG\Public\Blueprint\UserWidget.h    1420

    this is the code of my custom widget

    Code:
    // Fill out your copyright notice in the Description page of Project Settings.
    
    #pragma once
    
    #include "CoreMinimal.h"
    #include "Blueprint/UserWidget.h"
    #include "SGameplayWidget.generated.h"
    
    /**
     * 
     */
    UCLASS()
    class CASTLEVERSUS_API USGameplayWidget : public UUserWidget
    {
        GENERATED_BODY()
    
    };

    Leave a comment:


  • replied
    You can create a WidgetBlueprint and THEN use reparent to reference your c+ widget

    Last edited by DonFrag; 11-28-2019, 09:01 AM.

    Leave a comment:


  • replied
    Originally posted by SolidSk View Post
    I also had this problem, I think it's a known issue if you inherit the UserWidget from a C++ class.
    What I do is:
    1. Create a UserWidget from your Content folder: Right click -> User Interface -> Widget Blueprint
    2. Create a C++ class inherit from UserWidget.
    3. Change the UserWidget blueprint Parent Class to your C++ class.
    Click image for larger version

Name:	UserWidget.png
Views:	178
Size:	196.6 KB
ID:	1691098



    This is a little unnecessary overhead as it does nothing different from what the base class already does. So you can remove you Initialize() method.
    The workaround does do the job thanks
    But it is kinda weird they didn't fix it.

    Leave a comment:


  • replied
    I also had this problem, I think it's a known issue if you inherit the UserWidget from a C++ class.
    What I do is:
    1. Create a UserWidget from your Content folder: Right click -> User Interface -> Widget Blueprint
    2. Create a C++ class inherit from UserWidget.
    3. Change the UserWidget blueprint Parent Class to your C++ class.
    Click image for larger version

Name:	UserWidget.png
Views:	178
Size:	196.6 KB
ID:	1691098

    Also do not override functions if you just call their super functions as good practice.
    This is a little unnecessary overhead as it does nothing different from what the base class already does. So you can remove you Initialize() method.

    Leave a comment:


  • replied
    Originally posted by andrea.b View Post

    Also do not override functions if you just call their super functions as good practice.
    Can you tell me why ?

    Leave a comment:


  • replied
    Originally posted by andrea.b View Post
    Try to change this:
    Code:
    UCLASS() class LOST_API UPlayerUserWidget : public UUserWidget
    To this:
    Code:
    UCLASS(BlueprintType, Blueprintable) class LOST_API UPlayerUserWidget : public UUserWidget
    Also do not override functions if you just call their super functions as good practice.
    That didn't work as well

    Leave a comment:


  • replied
    Try to change this:
    Code:
     
     UCLASS() class LOST_API UPlayerUserWidget : public UUserWidget
    To this:
    Code:
     
     UCLASS(BlueprintType, Blueprintable) class LOST_API UPlayerUserWidget : public UUserWidget
    Also do not override functions if you just call their super functions as good practice.

    Leave a comment:


  • replied
    Originally posted by Sirgomo View Post
    Hello,
    i think you need to initialize it

    virtual bool Initialize() override;

    bool UPlayerUserWidget::Initialize()
    {
    bool bInit = Super::Initialize();
    return bInit;
    }
    I have added it and it didn't work
    Any other advice?

    Leave a comment:


  • replied
    Hello,
    i think you need to initialize it

    virtual bool Initialize() override;

    bool UPlayerUserWidget::Initialize()
    {
    bool bInit = Super::Initialize();
    return bInit;
    }

    Leave a comment:


  • replied
    Originally posted by GarnerP57 View Post
    Widget.h is the base class without the designer. You need to derive from UserWidget.h to get the designer.

    If you make a widget derived from Widget.h in C++ then you can still add it in another Widget Blueprint but you won't get a designer to modify it.
    but i am deriving from UUserWidget
    header file:
    Code:
    #include "CoreMinimal.h"
    #include "Blueprint/UserWidget.h"
    #include "Runtime/UMG/Public/UMG.h"
    #include "PlayerUserWidget.generated.h"
    
    /**
     * 
     */
    UCLASS()
    class LOST_API UPlayerUserWidget : public UUserWidget
    {
        GENERATED_BODY()
    
    public:
    
        UPlayerUserWidget(const FObjectInitializer& ObjectInitializer);
    
        virtual void NativeConstruct() override;
    
        void UpdateComboCount(int32 Value);
    
        void ResetCombo();
    
        UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidget))
        class UTextBlock* TXTCombo;
    
    
    };

    Leave a comment:


  • replied
    Widget.h is the base class without the designer. You need to derive from UserWidget.h to get the designer.

    If you make a widget derived from Widget.h in C++ then you can still add it in another Widget Blueprint but you won't get a designer to modify it.

    Leave a comment:


  • started a topic C++ Widget

    C++ Widget

    Hello,
    i am new to unreal engine and tried to make a widget class.
    I made a blueprint out of the widget but i cant find the designer button.
    Can any one show me how to open the designer?
    I am using UE 4 Version:4.23.1
    Click image for larger version

Name:	example.png
Views:	276
Size:	189.2 KB
ID:	1690545
Working...
X