Announcement

Collapse
No announcement yet.

Help! How do I set the value of a boolean variable when the player hits a trigger?

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

    Help! How do I set the value of a boolean variable when the player hits a trigger?

    Ok, so first some context!
    This script, which was made in the character blueprint, makes it so that when I press the left mouse button, I throw a grenade, which destroys itself within a set amount of time:

    Click image for larger version

Name:	grenade.PNG
Views:	2
Size:	103.6 KB
ID:	1225050

    The "Add Grenade Ability" node or function that you see in there, houses this:

    Click image for larger version

Name:	grenade2.PNG
Views:	2
Size:	79.0 KB
ID:	1225051

    Then the SpawnActor Grenade node is linked to this Blueprint Class, which is an actor:

    Click image for larger version

Name:	grenade3.PNG
Views:	2
Size:	119.5 KB
ID:	1225052


    The grenade throwing is fine, the cooldown and delay is fine.
    However, what I want to do is to have my grenade throwing abilities disabled at the start of the game. My grenade throwing abilities, I want it to be enabled when I hit a trigger. Hope that makes sense

    So I'm guessing that I have to figure out how to set the value of that boolean variable ( I named it ignore input) when the player hits the trigger.
    How do I do that? Also, I need to do this in a way where if the player beats that level and starts the next level, the player should still retain his/her grenade throwing ability.

    If possible, screenshots of an example would really help, as I'm more of a visual learner and as a complete newbie, I don't understand all of the jargon.
    Last edited by travisc; 07-08-2017, 04:42 AM.

    #2
    Hi Travis essentially what you want is this:

    Create a GameInstance Blueprint, call it something like MyGameInstance (Because this instance will persist when switching levels), then assign it to your game under the project settings tab Maps and Modes

    Next add a bool (ie PlasmaGranatLauncher) to the instance and categorize it as Items
    Then go to your Player BP and on the Tick event add a branch where you setup another new bool, call that EnablePlasmaGranatLauncher. Also add here after the branch a cast to your MyGameInstance and set the corresponding bool to true, once the on tick event fires.
    Now for the trigger place open the map view and type trigger in the Modes box (where those tools are located, or navigate to it under the Volumes panel), select the Trigger Volume and place into the map
    When the trigger box is scaled to your needs right click it in the World Outliner, then go to the Add Event, and choose OnBeginOverlap, the blueprint which pops up is the actual level blueprint, add here add a "Cast to MyPlayerBP" to the newly create On BeginOverlap event - plug that into the "other actor" of the OnBeginOverlap event of the trigger volume, then from the cast node to your player make a get PlasmaGranatLauncher and set it to true. Also add a DoOnce node inbefore the cast node because we only need to use the trigger once (otherwise it will keep casting when re-entering the volume).

    Last, add another cast node to your player blueprint to the EventBeginPlay, cast to MyGameInstance and get the PlasmaGranatLauncher bool, then set your bool IgnoreInput accordingly.
    Last edited by unit23; 07-08-2017, 05:25 AM.
    [LEGENDS of EPICA]

    Comment


      #3
      Originally posted by unit23 View Post
      Next add a bool (ie PlasmaGranatLauncher) to the instance and categorize it as Items
      Hi unit, I just started following your method, but I don't know what you mean by "categorize it as Items". So far I just made a variable I called "GrenaderEnabler", made it a boolean, within MyGameInstance blueprint, and dragged it onto the event graph. Not sure where to go from there.

      If there's like a youtube video or perhaps a screenshot of how it should look, that would help loads.
      Last edited by travisc; 07-08-2017, 05:36 AM.

      Comment


        #4
        Originally posted by travisc View Post
        Hi unit, I just started following your method, but I don't know what you mean by "categorize it as Items". Is it something I right click on the variable, or?
        This is for keeping a blueprint clean (optional), can be set when you select the bool variable and type a custom category name into the category text box (default is Default).
        [LEGENDS of EPICA]

        Comment


          #5
          Originally posted by travisc View Post
          Hi unit, I just started following your method, but I don't know what you mean by "categorize it as Items". So far I just made a variable I called "GrenaderEnabler", made it a boolean, within MyGameInstance blueprint, and dragged it onto the event graph. Not sure where to go from there.

          If there's like a youtube video or perhaps a screenshot of how it should look, that would help loads.
          You only need the bool setup in the game instance, that is all we do here in that blueprint, no need to place it in the event graph (and i didn't wrote that), Go on with the next step. Ask here for more pointers (My Unreal is currently working, cannot make screenshots atm)
          [LEGENDS of EPICA]

          Comment


            #6
            Originally posted by unit23 View Post
            add here add a "Cast to MyPlayerBP" to the newly create On BeginOverlap event - plug that into the "other actor" of the OnBeginOverlap event of the trigger volume,
            Alrighty, appreciate the explaination, but now I'm stuck on this part. I'm not sure what "other actor" refers to. So far, this step looks like this:
            Click image for larger version

Name:	dunno.PNG
Views:	1
Size:	106.4 KB
ID:	1130786

            Comment


              #7
              Just plug the cast nodes Object to the "Other Actor".
              [LEGENDS of EPICA]

              Comment


                #8
                Originally posted by travisc View Post
                ...
                ........................... pinging you
                [LEGENDS of EPICA]

                Comment


                  #9
                  Originally posted by unit23 View Post
                  ........................... pinging you
                  Ok, I just got that part figured out.
                  Click image for larger version

Name:	dunno2.PNG
Views:	1
Size:	39.4 KB
ID:	1130787

                  "then from the cast node to your player make a get PlasmaGranatLauncher and set it to true."

                  Do you mean go to my character blueprint and do something?

                  Also, what do you mean pinging me? (I'm new to these forums)

                  Comment


                    #10
                    Originally posted by travisc View Post
                    Ok, I just got that part figured out.
                    [ATTACH=CONFIG]147757[/ATTACH]

                    "then from the cast node to your player make a get PlasmaGranatLauncher and set it to true."

                    Do you mean go to my character blueprint and do something?

                    Also, what do you mean pinging me? (I'm new to these forums)
                    From your above screenshot - Right click the blue output As Actual First Person Character then type into the popup search get PlasmaGranatLauncher (After you have created such a bool var inside your actual First Person Character bp (and compiled it).

                    Notice, you might have to untick in the popup search window "context sensitive", because with it enabled the search is limited to your current blueprint and related nodes.
                    Last edited by unit23; 07-08-2017, 06:31 AM.
                    [LEGENDS of EPICA]

                    Comment


                      #11
                      Originally posted by travisc View Post
                      Also, what do you mean pinging me? (I'm new to these forums)
                      There should be a orange notification alert in the upper right corner of the forum, when i quote you. Then you know i've responded here.
                      [LEGENDS of EPICA]

                      Comment


                        #12
                        Ok, not sure if I followed it correctly, but so far on the level blueprint, it looks like this: Click image for larger version

Name:	dunno4.PNG
Views:	1
Size:	129.5 KB
ID:	1130789
                        Attached Files
                        Last edited by travisc; 07-08-2017, 06:48 AM.

                        Comment


                          #13
                          Actually what we need is to set the EnableGrenadeLauncher to Set (not get).

                          The part with Event BeginPlay goes onto your Player blueprint (loading once you switched/load levels)
                          [LEGENDS of EPICA]

                          Comment


                            #14
                            Originally posted by travisc View Post
                            ...
                            ............................ping
                            [LEGENDS of EPICA]

                            Comment


                              #15
                              Originally posted by unit23 View Post
                              Actually what we need is to set the EnableGrenadeLauncher to Set (not get).

                              The part with Event BeginPlay goes onto your Player blueprint (loading once you switched/load levels)
                              Ok, This is how it's like in the lvl blueprint:

                              Click image for larger version

Name:	dunno4.PNG
Views:	1
Size:	93.7 KB
ID:	1130790

                              In the character blueprint, I got an error. Don't know what I should connect to that error node. Then again, not even sure if I did this part properly:
                              Click image for larger version

Name:	dunno5.PNG
Views:	1
Size:	132.7 KB
ID:	1130791

                              Here's a more wider screenshot of the character blueprint:
                              Click image for larger version

Name:	dunno7.PNG
Views:	1
Size:	185.0 KB
ID:	1130793
                              Attached Files
                              Last edited by travisc; 07-08-2017, 07:09 AM.

                              Comment

                              Working...
                              X