Announcement

Collapse
No announcement yet.

C++ Widget

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

    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:	279
Size:	189.2 KB
ID:	1690545

    #2
    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.

    Comment


      #3
      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;
      
      
      };

      Comment


        #4
        Hello,
        i think you need to initialize it

        virtual bool Initialize() override;

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

        Comment


          #5
          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?

          Comment


            #6
            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.

            Comment


              #7
              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

              Comment


                #8
                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 ?

                Comment


                  #9
                  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:	180
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.

                  Comment


                    #10
                    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:	180
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.

                    Comment


                      #11
                      You can create a WidgetBlueprint and THEN use reparent to reference your c+ widget

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

                      Comment


                        #12
                        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()
                        
                        };

                        Comment


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

                          Comment

                          Working...
                          X