How to make object that unlocks the baricade

Hi, I have a question. I’m trying to make a 2D game. I have an object that I want to use as a key to open a path that is blocked by a barricade. I’ll put pictures here so you can visualize it. I’m using blueprints and I don’t know how to make it so that if I pick up a coin and go to the barricade it disappears and if I don’t have a coin it doesn’t disappear.


obrázek_2022-12-10_224101459

1 Like

Greetings @MrJerody !

We warmly welcome you to the Unreal Engine community! :medal_sports:

Just so you’re aware, this topic has been moved from the International forum category to the Development - Programming & Scripting - Blueprint forum category.

Just remember, when posting, please review the categories to ensure your topic is posted in the most relevant space.

Wishing you the best in a resolution to the issue you’re having,

Your Friendly Neighborhood Moderator :smiley:

Hello MrJerody,

You must create a variable of type bool, you set this variable to true when you pick up the key.
On your barricade you add a Trigger, and if the bool is True, you can pass.

I’m sorry, but I don’t quite get it. I added a bool to the coin. I don’t know what to do with it. Maybe a sample of my blueprint would help.

So this is a coin


and this is barricade

Be careful, you must set your bool to True before destroying your Actor, otherwise it cannot access your variable anymore.
Here is an example you can use:

BP Coin

BP Barricade

How did you get BP Coin at the BP Barricade?

You simply create a variable of type BP_Coin

It threw this error.

And my blueprints are like this
BP Barricade


BP Coin
image

In the BP_Barricade, in the Event Begin, cast to the BP_Coin and set your variable with.

Thanks for helping me. I’m a beginner so it’s harder for me.

Now it’s throwing this error.

BP Barricade

Do you have more than one BP_Coin in your scene?

Since you are destroying your BP_Coin I think it is best to put your variable in your PB_Player

No, I don’t.
If that’s what you mean.
image

Create the Bool variable in your BP_Player. When you pick up the coin, you pass it to True and you check at the end in the BP_Barricade.

BP Coin

BP Barricade

I’m sorry but i don’t get it.

I have created this variable in my BP_Player.

BP_Coin

BP_Barricade

In the Bp_Coin, you have to get the variable from the output node (blue).
And in BP_Barricade, you didn’t do anything like I explained.

I didn’t know what to do in BP_Barricade. But now I understand that I have to get the variable out of it (blue) just like I did with the coin.

But now I can’t pick up the coin.

And it throws error again


I don’t think I’ll ever be able to do that.

BP_Barricade

BP_Coin

You have to delete the Picked variable in BP_Barricade and create it in your Player_Astronear.

I already did that.

Here is BP_Player

Here is BP_Coin

And here is BP_Barricade

Your BP_Barricade is not good, look at what I showed you in a previous post.