Announcement

Collapse
No announcement yet.

How to disable a specific key in Blueprint?

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

    How to disable a specific key in Blueprint?

    In my character blueprint I have it where the player can turn on and off a flashlight by using the "F" key. What I want to do is have my "F" key disabled at the start of my level and then enable it when I collect a flashlight. How would I do this? I have been looking for hours and trying everything I can think of but I can't seem to find a straight answer. Can someone please show me an example blueprint if possible? Thanks!

    #2
    Create a boolean variable on the character with a name like 'enableFlashlight'. Set this variable to false when the player doesn't have a flashlight and then set it to true when they collect the flashlight.

    Then, on your key press event, do a 'branch' test for that boolean variable to see whether they should be allowed to turn on the flashlight. If they are, turn it on.
    The guy that makes the wheels turn..

    Comment


      #3
      Originally posted by Mellark View Post
      Create a boolean variable on the character with a name like 'enableFlashlight'. Set this variable to false when the player doesn't have a flashlight and then set it to true when they collect the flashlight.

      Then, on your key press event, do a 'branch' test for that boolean variable to see whether they should be allowed to turn on the flashlight. If they are, turn it on.
      Is there any way that you can post a picture of what you told me? Sorry, I am just a bit lost on this one. I get what you are saying but I just can't seem to visual see it. It would really help me out. Thanks!

      Comment


        #4
        Or if your code is too spread out / messy to follow Mellark's bool idea:
        Connect 'F pressed' to a Gate Node (ensure Start-Closed is left ticked).
        Add Custom Event 'EnableFlashLight' and link it to the Gate 'Open' pin.
        Then call EnableFlashLight from whatever code enables the pickup etc.

        Comment


          #5
          Originally posted by franktech View Post
          Or if your code is too spread out / messy to follow Mellark's bool idea:
          Connect 'F pressed' to a Gate Node (ensure Start-Closed is left ticked).
          Add Custom Event 'EnableFlashLight' and link it to the Gate 'Open' pin.
          Then call EnableFlashLight from whatever code enables the pickup etc.
          How would this work when it comes to saving the state of the game? Would he have to do an inventory check on game load then? I'm assuming he wants to save the game, but if he doesn't I'm curious to know myself.

          [MENTION=213]bigboy2k[/MENTION] I would post a picture, but I'm not near a PC equipped with Unreal Engine and I won't be for a few hours. If I find time tonight and you still need help I will work on a screenshot for you.

          I will try again to explain what I mean though. I'm assuming you've created the variable. Basically, whenever your character picks up the flash light, you want to 'Get Player Character' and connect that to 'Set Enable Flashlight' (or whatever the name of your variable is). Then, on your 'F key press' event, you want to connect a branch node. The boolean input for this branch node is the value of your Enable Flashlight variable. For this, you would need a 'Get Enable Flashlight' node. When your branch returns true, you can turn on the flashlight. When the branch returns false, just do nothing.

          Hopefully that helps a little more.
          The guy that makes the wheels turn..

          Comment


            #6
            Originally posted by Mellark View Post
            How would this work when it comes to saving the state of the game? Would he have to do an inventory check on game load then? I'm assuming he wants to save the game, but if he doesn't I'm curious to know myself.
            Save game wasn't mentioned, but I agree bools are best for saving.
            However bools can be confusing when starting out. See this example.
            Whereas with a Gate, the flow is clearer, off until custom event called.
            BTW: Flip-flop nodes will help with toggling the flashlight on / off after.

            Comment


              #7
              Originally posted by franktech View Post
              BTW: Flip-flop nodes will help with toggling the flashlight on / off after.
              That is a good point. I forget about that node more then I should.
              The guy that makes the wheels turn..

              Comment


                #8
                Originally posted by Mellark View Post
                How would this work when it comes to saving the state of the game? Would he have to do an inventory check on game load then? I'm assuming he wants to save the game, but if he doesn't I'm curious to know myself.

                [MENTION=213]bigboy2k[/MENTION] I would post a picture, but I'm not near a PC equipped with Unreal Engine and I won't be for a few hours. If I find time tonight and you still need help I will work on a screenshot for you.

                I will try again to explain what I mean though. I'm assuming you've created the variable. Basically, whenever your character picks up the flash light, you want to 'Get Player Character' and connect that to 'Set Enable Flashlight' (or whatever the name of your variable is). Then, on your 'F key press' event, you want to connect a branch node. The boolean input for this branch node is the value of your Enable Flashlight variable. For this, you would need a 'Get Enable Flashlight' node. When your branch returns true, you can turn on the flashlight. When the branch returns false, just do nothing.

                Hopefully that helps a little more.
                Thanks Mellark and franktech for your help

                Unfortunately I still can't get it to work

                Sometimes I am just more of a visual learner. Hopefully I can get some screenshots to help me with this. Thanks again!
                Last edited by bigboy2k; 02-09-2017, 03:16 AM.

                Comment


                  #9
                  Originally posted by Mellark View Post
                  How would this work when it comes to saving the state of the game? Would he have to do an inventory check on game load then? I'm assuming he wants to save the game, but if he doesn't I'm curious to know myself.

                  [MENTION=213]bigboy2k[/MENTION] I would post a picture, but I'm not near a PC equipped with Unreal Engine and I won't be for a few hours. If I find time tonight and you still need help I will work on a screenshot for you.

                  I will try again to explain what I mean though. I'm assuming you've created the variable. Basically, whenever your character picks up the flash light, you want to 'Get Player Character' and connect that to 'Set Enable Flashlight' (or whatever the name of your variable is). Then, on your 'F key press' event, you want to connect a branch node. The boolean input for this branch node is the value of your Enable Flashlight variable. For this, you would need a 'Get Enable Flashlight' node. When your branch returns true, you can turn on the flashlight. When the branch returns false, just do nothing.

                  Hopefully that helps a little more.
                  Please, does anyone have a visual representation of what was explained above? I would really appreciate it as I am still lost on this one.

                  Maybe someone can also answer a question I am wondering about when it comes to this whole process. Why isn't there a "disable input" for a specific key in blueprint? Wouldn't that make this whole process so much easier?

                  Comment


                    #10
                    Here's a quick mockup I made:

                    Click image for larger version

Name:	477e4354be6f90c9c614b7f22610742f.png
Views:	1
Size:	122.7 KB
ID:	1122827

                    You would still need a way to set the value of that boolean variable when you pick up the flash light, and obviously fill out the turn on and turn off flashlight events. Hopefully this helps
                    The guy that makes the wheels turn..

                    Comment


                      #11
                      Thanks Mellark! This really helped

                      Comment


                        #12
                        Not a problem! Glad I could be of assistance!
                        The guy that makes the wheels turn..

                        Comment

                        Working...
                        X