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:

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

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

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 :slight_smile:

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.

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.

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.

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).

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)

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:

Just plug the cast nodes Object to the “Other Actor”.

… pinging you

Ok, I just got that part figured out.

“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.

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.

Ok, not sure if I followed it correctly, but so far on the level blueprint, it looks like this:

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)

…ping

Ok, This is how it’s like in the lvl blueprint:

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:

Here’s a more wider screenshot of the character blueprint:

You also need to connect the output nodes of the player bp with the launcher var inside your level blueprint. The error above appears because you need to add a get gameinstance function node and plug it into the Object input of your instance node. While at it and to reduce the amount of casts, rightclick the blue output node of the game instance (in your player blueprint), and create a new variable, call it MyGameInstanceRef (for reference). You then can use this new var everywhere in your player blueprint, when calling the gameinstance. Also the Event Tick branch should not point to the game instance.

Not sure if I understood everything here, but this is what I came up with. What should I do with the “Event Tick”? (This is the character BP)

Do not merge Tick and BeginPlay here.

The set MyGameInstanceRef belongs to the corresponding Cast to MyGameInstance, thus plug both together inside the Event BeginPlay. You can use a variable as many times you want, so no need to move the events so close together, which will become a visual overview issue, as the project grows.

Event Tick after the branch node, first drag and drop the newly created MyGameInstanceRef to the Event Tick area, then from that variable (right click the output) add a Set GrenaderEnabler (or it appears you renamed it to GrenadeLauncher) via the search popup and check the bool to be true.

Also for the Event Begin Play, it should look like this
example.jpg

Axe would correspond to your EnableGrenadeLauncher bool

Also add a do once node after the Event Tick branch, to prevent firing this event branch over and over again.

alrighty, that makes more sense. Still isn’t working though. The player isn’t able to use grenades even after hitting to trigger volume. This is how it looks now: