Announcement

Collapse
No announcement yet.

Build error in C++ using Widgets

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

    Build error in C++ using Widgets

    Hello everyone

    I'm having an issue with Widgets that are declared in C++

    In the private member variable class UMainMenu* Menu that attributes is set to private:


    No problems there. However when declaring the methods with it's implementation I'm getting a build error within the InGameLoadMenu() where it is stating on line 48 that "declaration of 'Menu' hides class member"


    Okay I said to myself this is new? When I commented out the statement of UMenuWidget* Menu = CreateWidget<UMenuWidget>(this, InGameMenuClass); it builds just fine. Vice versa it throws the same build error.

    Can anyone assist in finding a way to change the syntax so it builds safely and correctly without, seeing this error. I have a github account but it is set to private, for anyone that wants to see the code in full, my github account tag name is: brandonfullerue4sc

    Many thanks for any assistance and for the time in reading this issue.
    Brandon

    #2
    What I would do:

    .h
    Code:
    UPROPERTY()
    class UMainMenu* Menu;
    .cpp
    Code:
    // I didn't understand why you are using another type here.
    // UMenuWidget* Menu = CreateWidget<UMenuWidget>(this, InGameMenuClass);
    
    Menu = CreateWidget<UMainMenu>(this, InGameMenuClass);
    If there is other errors could you post your .h and .cpp file? Only UUserWidget part.

    Comment


      #3
      I normally use my playercontroller to Build UserWidgets (I have no idea if that's the right way to do it just how I've normally done it).

      my .h File looks like this:
      Code:
      UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Menu's")
      TSubclassOf<UUserWidget> Menu;
      
      class UMenuClass* MainMenu;
      My .cpp file looks like this.
      Code:
      MainMenu = CreateWidget<UMenuClass>(this, Menu);
      I have found that it's good practice to check that those aren't null before moving on.
      From here I just set up the player controller blueprint to have the Menu widget.

      The error you're getting would probably be fixed by moving line 38 to public:

      Comment


        #4
        You're redeclaring a variable with the same name. If you read the output log it tells you what the error is. Remove `UMenuWidget*` from line 48

        Comment


          #5
          Originally posted by TheJamsh View Post
          You're redeclaring a variable with the same name. If you read the output log it tells you what the error is. Remove `UMenuWidget*` from line 48
          Oh snap you're right. Good catch.

          Comment


            #6
            James.Harvey TheJamsh Oh wow - I didn't see it. I'll check when I'm coding it using this first thing tomorrow morning. Thanks for all the support and kind comments. As I state this is helping me to become a better programmer. Because of my physical disability I'm trying to re-educate my logical way of thinking from the stroke I had as a baby. Using C++ helps with that rehabilitation. So if in future I get the syntax of my grammar wrong I hope this excellent community can understand what the aims are. In fact why wait till tomorrow? Just booting up my laptop now. Thank you so very much for all the support! Best regards and have a wonderful holiday and a great New Year for 2020. Brandon

            Comment


              #7
              Oh and how could I forget @Solid.Sk for your valuable contribution. Humbled I'm sure. Have an excellent holiday and a wonderful 2020. Brandon

              Comment

              Working...
              X