Announcement

Collapse
No announcement yet.

Using a UMG button to select a character

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

    Using a UMG button to select a character

    Is it possible to select a character by using a button created within the UMG? I have 5 characters, all of whom are set out within the level when the game starts.

    The idea is that the player will be able to select a character, move it, and then select another character to move, either to join the previous one, or go off in another direction. I could setup an option to click upon the character model and possess each character individually but this wouldn't work if the other character(s) were out of view. By using a UMG button I would be able to select a character even if one is out of visible range.

    I'm looking to create the game using touch input rather than a keyboard so my options for using a key select for a desired character are not an option.

    I have built the buttons but I can't seem to find an option to interact with my character models within the button's graph/blueprint.

    At present I'm making use of the TopDownController from the default templates which at this time controls just the default 'PlayerStart' character.

    https://answers.unrealengine.com/sto...2015.09.27.png

    I have four test characters in the game at the moment which consists of a 'PlayerStart' node and three characters dropped into the scene. At the moment they are BulldozerCharacter (a repeat of the PlayerStart), Bulldozer2Character and Bulldozer3Character

    https://answers.unrealengine.com/sto...2015.09.44.png

    I'm using the TopDownGameMode which references the BulldozerCharacter as the Default Pawn Class.

    https://answers.unrealengine.com/sto...2015.11.18.png

    When the game is in 'Play' mode I have three buttons in the scene which are 'Ch1' (Character 1), Ch2 (Character 2) and Reset. These are only for test purposes - more would be used in the final layout.

    https://answers.unrealengine.com/sto...2015.18.28.png

    As I say, my aim would be to have it so that the player taps/drags on the screen to move the character around at the time of playing the game but when they want to change character, they can tap on the button to select another.

    This is to be aimed at young children so it has to be kept simple. I did initially plan to have it that the characters were tapped on but of course this doesn't work when they go out of view of the other models. At the moment, the setup is that each character (vehicle) has its own camera on a springarm.

    Any help would be greatly appreciated as I'm now at an impasse that is holding up the rest of my game's development.
    Last edited by BarryC; 05-19-2015, 06:58 AM. Reason: Spelling error

    #2
    I'd create an actor variable (say "PlayerCharacter") in the UMG widget you're using to select the character to be controlled. Then whenever you create the widget from your player blueprint set "PlayerCharacter" to self. Then in your UMG widget OnClick event just unpossess "PlayerCharacter" and possess the new pawn as PlayerCharacter. I've not tried anything like that personally but I'd think it should work.

    Comment


      #3
      You have to set up your controller to possess the character you want. To talk to your controller bp from UMG, I would suggest using a BP interface. Create an interface and add it to your controller. You need to set up one function and set a varible you are going to use determine which character to select. I used an int since it is easy to work with an array.Click image for larger version

Name:	TD_BPI.PNG
Views:	1
Size:	118.4 KB
ID:	1075799

      Next, Create a variable in you Controller to hold the character variables. Also, set up the event from the interface to change possession.Click image for larger version

Name:	TD_Cont.PNG
Views:	1
Size:	253.2 KB
ID:	1075800

      I quickly dragged and dropped four players in the world and referenced them in the to the level bp, created an array, and sent it to the controller. I also created and added my widget to the viewport here. I would not do this stuff here in an actual game.Click image for larger version

Name:	TD_LevelBP.PNG
Views:	1
Size:	243.0 KB
ID:	1075801

      Finally, I created my widget with four buttons to select each character. I sent a message to the Controller interface with the int I wanted for each character. Click image for larger version

Name:	TD_UMG.PNG
Views:	1
Size:	209.8 KB
ID:	1075802

      Actually, the last thing I did was test it.Click image for larger version

Name:	TD_ingameWorking.PNG
Views:	1
Size:	159.9 KB
ID:	1075803

      It worked!

      -James

      Comment


        #4
        Thanks for this James, especially considering the time and effort involved to supply blueprint screenshots (they make it soooo much easier to follow). I can't wait to try this out later once the kids are in bed and I can start working on this again

        Comment


          #5
          No problem, didn't feel like working on my stuff yesterday so I went through and tried to answer as many questions as I could. AS for the images, setting up BPs and taking screen shots is a lot quicker for me than trying to type all that out in an understandable way, and I can make sure that what I think is going to work does work; it helps me try new things.

          Let me know if this does work out for you.

          Comment


            #6
            Hi James, Can I just check, the 'Chars' variable that was added to the TopDownController, what Variable Type was it? I changed it to an array but then suddenly realised that there was a whole load of options

            Once again many thanks for your help on this

            Comment


              #7
              Since you are putting Characters in it use a character array. Once you select the var you can type in the type you want in the search to find it easier

              Comment


                #8
                Hi James, sorry to keep pestering you on this one - so close to getting a working setup now but have realised that by trying to add unique characters (rather than dragging and dropping repeats of TopDownCharacter) doesn't work within the array. Is there something. Is there a way to link unique character blueprints to the same array?

                Click image for larger version

Name:	Screenshot 2015-05-08 00.11.25.png
Views:	1
Size:	285.7 KB
ID:	1075935

                Once more - a big thanks for your help so far.

                Comment


                  #9
                  Yes! When you call "Make Array" its data type automatically gets set to the first thing you put in it. Instead, create a variable and set it to the base type of your actors. In the case below I used the Maximo Animation pack, I could have set the array to the base Maximo character, but instead I set it to "Character". If some of your "players" are not bipeds using the character class, set it to pawn. Then add them in to your array. Make sure the array in your other blueprint is set to the same data type.

                  Click image for larger version

Name:	4Players.PNG
Views:	1
Size:	353.2 KB
ID:	1075938

                  Comment


                    #10
                    James, you are a superstar! Thanks for this - I'll be sure to test this tonight

                    Comment


                      #11
                      James, cannot thank you enough for this. I tried out your new array layout and it's worked an absolute treat!! Finally I can move on the next stage and start building the models knowing that I have a working navigation system in place

                      Comment

                      Working...
                      X