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:
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
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.
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.
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)
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.
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.
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
Axe would correspond to your EnableGrenadeLauncher bool