[HELP] Best way to open a door

So i have a door blueprint that opens and shows text like Door Open or Door Closed, but the text shows even when im not looking at the door and i can still open and close when im not looking or in front of the door, what i think may be the best way to open and close a door with showing text would be to check if im in a certain radius within the doors position and raycast to check if im looking at the door when i click a button. How would i go about doing this ? I made a c++ project because i want to learn more of a programming side than to learn blueprints so im not sure how to make a character blueprint from my characters camera to make a raycast.

Here’s what my door blueprint looks like:

And this is what it looks like in game:

Hey,

This might be useful for you: https://docs.unrealengine.com/latest/INT/Gameplay/HowTo/UseRaycasts/Blueprints/index.html

You can use a single line trace to check if you’re looking at a door. You can even limit the range of the line trace, so that you can only use the door from a certain range (this way you can get rid of the volume completely).

Hope this helps!

If you plan to use cpp : this might help.wiki.unrealengine.com/Trace_Functions from rama. Dont forget to ignores your actor and use actor forward vector as a direction of your traces.

This isn’t working Screenshot - ae998c6c817c98c148062122214eeec9 - Gyazo

What exactly isn’t working? Is the line trace firing as intended? Can you see the red lines? Does it hit the door (is there a red square on it?) What is the print string outputting?

I got it working, the only thing i need to do now is figure out how to notify my door blueprint that i am looking at a door.

First use get class on the hit actor and do an equal (class) to check if the actor you hit is a door blueprint. If it is a door blueprint, then cast to that particular blueprint (use cast to doorBP and make sure to specify the hit actor as the target to cast to) as the doorBP you can then run a custom event (or function) that opens the door :slight_smile:

I can go into a bit more detail if you wish and post up an example.

Yeah i’m not really sure if i understand, i’m a beginner. I would love for you to explain.

Alrighty here you go:

First off you need to create a custom event in the doorBP that opens the door. (And probably one that closes the door)

Then inside the character blueprint after the trace you do something like this:

Get class - gets the actual class of the actor. For example if the actor is an instance of your door blueprint, it will have a door blueprint class. This is important for the next step

Equal (class) - this compares 2 classes and returns true if they are equal and false if they are not. We could just use an equal (object) directly with the actor instead of having to use get class, but then we would compare the actual INSTANCE, not the class. (This is also why when the trace hits the door it doesn’t say DoorBP in the print string, but rather something like DoorBP_C1 etc. This is a problem, as we have nothing to compare the instance to. We would have to directly reference that instance, which is not possible unless the whole script is inside the level blueprint. Therefore we compare the CLASS, which is the same for every instance. (MAKE SURE that you select the door blueprint from the drop down menu)

A branch is your usual “if” function, that checks if a boolean is true or false and runs accordingly.

Finally we are using casting. Casting basically means you “become” the blueprint. You can access all the public variables and functions within it that way. When you cast to a certain blueprint, you have to specify which instance you are casting to. In our case we want to cast to the door that we are looking at, that’s why we plug hit actor straight into object of the Cast To node.

Then drag from the As DoorBP output and you should be able to run the custom event that you created earlier.

Here is a bit more information on blueprint communicaitons and casting:
https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/BlueprintComms/index.html

and here:
https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/BlueprintCommsUsage/BPComHowTo/index.html

Hope this helps! :slight_smile:

Thanks, I got everything working.

No problem. Glad I could help :slight_smile: Would you mind choosing an answer so that this gets marked as solved?