How to open a door only if the player has a specific number of points?

To start off, sorry for using UE 4.9, but unfortunately have to as my college only has that version.

Okay, so I am making a game where you shoot at targets, and those targets will give you 10 points for each, I want to have it so that the player cannot open the door to the next room unless their score reads, for example, 40. I am new to Unreal and I have no idea how I would do this!

Any help would be greatly appreciated! Thank you in advance!

(If you could maybe post screenshots or a step-by-step bulletpoint list on what I need to do, that would probably help me a lot!)

The proper way to ask this type of question is to show the work you have already done. It sounds like this is some sort of homework assignment.

All you need to do is cast from the door to the player character and get the score variable, compare it to the min score needed, and if its greater then open the door.

I made some small project that has door, and some scores. Sadly Its in 4.11 because i do not have any older unreal builds.
Here is link: Dropbox - File Deleted

It also has example of dispatchers and interfaces, and some very basic HUD that displays points collected.
Also pickups that tell player they were collected etc.

Couldn’t he use a Blueprint Interface and make it modular? So he can save himself sometime.

i have a tip for you search on youtube for how to make a door that opens if you have 40 points in unreal engine 4

Maybe a little read up on variables can point you in the right direction. Using a variable to store the score and trigger the door opening animation is one way you can do it.

what Zyleq said is good advice. Create a variable of float or int and name it score, make it public, and increment it as necessary. Then have a branch who’s condition is that your score is 40, or whatever you want it to be, and then have that branch open the door if the condition is true. There are also many other ways to accomplish this.

This would be the most helpful comment so far, declare variables, create loops/nested loops and set the conditions :slight_smile:

this is just an idea that might help, im also new to unreal engine, you need to set up a system that increments each time the target is hit, each score surface should have an individual id, but the same math will be basically the same, each time the person hits the area it must update the hud saying +10 or something like that, the score area (where the total score is shown) should increase aswell, have the score amount set to a specific id. make an if statement that only runs if the door is activated, and set it to check if the score id equals to the target amount, if it does it opens, if not, it should tell the player that they are useless and need to go back and shoot some more. im not really good at explaining in txt format, and i have a weird sense of humor.

There’s several way to approach this. One method is to setup variables within your PlayerCharacter script (or wherever most of your variables are stored). Set a trigger instance for the door, a variable (integer) that calculates your current score, and perhaps a NoHolDor variable (integer) that has the 40 point value needed to trigger the door opening sequence. Using the HUD file you likely created for the game, the text box that holds the current score can be setup with a binding that translates the data that represents your score to a text format that you can later use for validating your conditions. In Blueprints, you can take the trigger event (while referencing your player of course) and create a branch to handle the actions (true/false) while declaring a condition (e.g. integer >= integer node) with the current score tapped into the upper input pin of the node and the NoHolDor variable in the bottom input pin of the same node.

One book I highly recommend is the Blueprints Visual Scripting for Unreal Engine by Brenden Sewell. It covers this in great detail and explains what you are practicing and why it’s important. Having spent most of my time in UDK while attending school for Game Design you can imagine how ****** I was when UE4 came out less than a year after I graduated. Now that I’ve had the chance to burn through lessons and realize UE4’s true potential I love it now more than ever.

Create Game Instance to Store Score Variable and Provide a Place to Access It, things in Game Instances are persistent and remain throughout the game.

**In your game Level Script/Blueprint add a variable reference to the Game Instance you created so you can easily access variables and functions in it. **

In your Game Instance add a Score variable of type Integer and create Add Score Function.

Create a Reset Score Function.

Create a Check Score Function.

Create a Get Current Score Function.

Here are the Function Blueprints.

Add Score Function:

Reset Score Function:

Check Score Function:
Get Current Score Function:

Create a Door Blueprint:

Create Door Animation, such as with a Matinee Actor or Timeline:

**Add a Matinee Actor variable to the Door Blueprint and create an event to play the animation when called, in the Details tab select your Open Door Matinee Actor containing your open door animation so it is linked with the Matinee Actor variable in the Door Blueprint so the Door Blueprint has access to the Matinee Actor in the level and the playback works.

**Now select the Door in the level and create a reference to it in the Level Script so the Level Script can access it and call the events, functions, or variables on it, then setup input to a test keyboard key like the T key, and compile and save everything after setting the Score Limit and Score Amount to add for each time the Add Score and Check Score functions are called.

Press Play and then press T key 4 times, you will see the score increment as it is printed to the screen, and once the T key has been pressed 4 times it will playback the open door animation once the score gets to 40. The score will automatically reset back to 0 and you can repeat the process.

The result is this Score 10, 20, and 30 on T Key 3 presses:
Score 30.jpg

And on the 4th T key press for Score 40 it plays the door animation, which how I set my animation moves the door to the right a bit.:
Score 40.jpg

The Unreal Engine Content Examples, the example Game Content and Templates, and online on YouTube are a good place to learn more, a lot of tutorials and examples are also on the official Unreal Engine YouTube channel, website, and in documentation online and the wiki.

If I had to give any good advice for a beginner, it would be try and keep things simple as much as possible and not overcomplicate, because we often get stuck and have tendency to focus so much on the details that the simple functionality for simple gameplay that is more complete could be done much faster with sticking to simple functionality, and it’s about what makes a game fun and enjoyable in the long run.

I feel like there is a much easier way to do this. I mean, you could simply Cast to the player like stated before, but in the door hold a variable called something like “Required Score” make it either a float (if you have a decimal value) or an integer (if its just a simple number like 10, 15 or 20) and then in the player blueprint, when the player tries to open the door run a quick check to see if the players current score (variable inside the player blueprint) is equal to or greater than the doors required variable, if so then open door. Really basic, really easy. You don’t need to make game instances or access 50 different blueprints to run a simple comparison between a current value and a required value. (I said put the required score in the door blueprint, because if you have a different door that requires a different score, then you can make that required score different than the first door, but the check against the door could be the same) If you need, I can literally setup a quick example in under 20 minutes for you.

While it may seem like a little of an overkill, adding a game instance is the proper way to do it.

Though the door design above is rather poor I my opinion. Definitely should a score variable be added, as SymCreations995 suggested. Additionally, the door should have a OnAttemptOpen event which is called every time the player tries opening it; this event will then check whether all prerequisites for opening the door are met: the prerequisite may just be score for now but in case the requirements change in a future version, it is easy to just change the event’s implementation right in the door. If you have the player check it, like above, this may lead to the player class becoming very complex and difficult to maintain. Also, having the player perform the check violates the single responsibility principle as it should only be handling player input (and therefore notifying the weapon to fire).

Ideally, you also add a target actor, or an actor component which marks its owning actor as target. Either way, the target should be notified when a projectile hits it and increase the score. In the approach of creating a target actor class, simply listen for an OnActorBeginOverlap or OnActorHit event, depending on who projectiles are set up to collide. In the approach of creating an actor component, you need to bind a callback function in C++ to the OnActorBeginOverlap or OnActorHit delegate object, again depending on how collisions are set up; it might be able to bind the parent actor’s overlap and hit events in a component in blueprints, too, though I am not sure how and hope somebody else will be able to answer that. By creating this target actor you take away the score updating responsibility from the player class. This way the player class will only have one responsibility: handling user input (which notifies a weapon to fire among other actions like walking, jumping, etc.). You could simply use the first person shooter template adding the door, and target classes.

By the way, you can find the single responsibility principle, which I used to justify my design, and four other very important ones right here.

What college are you going to?

just create 2 variables in your character blueprint (neededscore, score ) and in your door bp a cast to character , getting the values of both ,then score>=neededscore bool and then open door animation …you either create a hit event on the target which leads to a cast to character -->score+10 -->set score , or you do a line trace and compare the hit targets by breaking the result of the line trace… feel free to set as many printstrings for debugging as you wish :smiley: , its not necesary to cast all of that into game instance if you dont want to change maps during play and save this score until game close (gameinstance will save them until you close the game) the example of the guy above me is pretty epic though and far more detailed :slight_smile:

hello beemo_chop i would love to work with you towards this game im also new to unreal engine and would like to help