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