Line tracing issues

Hey guys,

I’m currently learning unreal for a university class and im making an elevator as part of my assignment. I’ve run into some errors when following this tutorial here: https://youtu.be/EXEOfcwXzn8

I’ve double checked that the line is being drawn and hitting the component of my elevator blueprint, and theres also no issue when i plug the function directly into the “move component to” node, the elevator is moves to the position specified.

so im assuming that theres possibly an issue between the line being traced and then comparing the tags of my components? I’ve already triple checked that my components have the correct tag attached to them so im quite stuck as to why no code is being executed at all. I’ve also fiddled around with the collision settings of the button to see if that would help, but nothing.

Heres a link to some images with my code for the line trace i made from the tutorial, as well as a visual of the line being traced

any help would be greatly appreciated :slight_smile:

Can you hook up a print string to “Cast to BP_Player” on “Cast failed” and see if maybe the code stops there…

Edit: I see and missread about the debug lines from the line trace. How about removing the “Do once” node and test if the code executes without it. Awso the make array i think you could remove it and test.

You could still put print strings after each of your tags / branches after them on true and false and see what fires

hi! thank you for helping, I’ve managed to pinpoint where its going wrong but I’m still unsure as to why. i used the “print string” node in different sections of the code and the only places it didn’t return anything was when i put it between the “component has tag” and “branch” nodes. so I’m assuming there’s something wrong with the way it recognizing the tags? since the branch will run the false to the next branch

if anymore information helps, it might be worth mentioning these buttons are a separate blueprint and are being nested in the elevator blueprint, and they’re also a skeletal mesh because they have some animation. I’m not sure if any of that could affect the way its recognizing the tag though

I tested something similar and i couldn’t make it work with component tags but this actor tag node works. You will have to connect it to “Break Hit result/Hit Actor”:
bandicam 2024-05-04 01-36-48-161
+
click on your button BP on the very top like on this screenshot and add actor tags instead of component and replace “component has tag” with from above this “actor has tag” nodes:

You can awso do some simple animation without the need for a skeletal mesh. In case of a simple “press button” animation you could do it with a timeline node which may be easier at the end.

Edit: Sly.Sk nailed it tough. I assume we miss this part and thats what is most probably whats causing the issue…

I think the most important thing to print is the name of the component hit. From your screenshot I suspect that you’re not hitting the button but I might be wrong.
To do that add a Print String after your line trace node and drag the node GetDisplayName from the Hit Component reference. If that’s not one of your button then you need to make sure that inside their collision settings their Object Type is World Dynamic, since it’s what your trace is looking for.

1 Like

Thats acctually a great idea maybe he just forget to set the right collision. Worth to double check for sure.

1 Like

Can you hook up a print string to “Cast to BP_Player” on “Cast failed” and see if maybe the code stops there…

Edit: I see and missread about the debug lines from the line trace. How about removing the “Do once” node and test if the code executes without it. Awso the make array i think you could remove it and test.

You could still put print strings after each of your tags / branches after them on true and false and see what fires

Can you hook up a print string to “Cast to BP_Player” on “Cast failed” and see if maybe the code stops there…

Edit: I see and missread about the debug lines from the line trace. How about removing the “Do once” node and test if the code executes without it. Awso the make array i think you could remove it and test.

You could still put print strings after each of your tags / branches after them on true and false and see what fires

hi! thank you for the suggestion, i tested it out and its returning the button component of my blueprint. should it be the exact same name as the component though, as it returns that its the blueprint, but its floorbutton"x"

heres hwo i plugged it in, and heres what its returning to me

edit: just realised its calling their name in the scene. so it’s definitely hitting the buttons

On getting the camera location: you might want to use the APlayerCameraManager instead of casting to the player character. It’s a cleaner approach and helps keep your Blueprint simple. You also won’t have to revisit this bp if the pawn ever changes.


Going a little off topic… I know your just starting, try to learn for curated youtube channels, reviewed courses and conferences. There is a lot of free content that will do more harm than good.

We should try to avoid this type of wiring and go for code that is easy to manage and iterate uppon.

Just imagine what it would look like programming an actual elevator with these features:

  • Press button, wait to close door if open and then move to floor.
  • When arriving at floor, open door, wait, close, then move.
  • Button to close door.
  • Button to open door.
  • Beep if door is open for too long.
  • Queue multiple buttons, make them glow when queued.
  • Clear all floors in a single direction before clearing the queue in the opposite direction.
  • Go to first floor if no queue.
  • SOS button to stop and sound an alarm, then turn off and continue.
  • Panel in each floor to call elevator (both up and down).

There are patterns to make these type of mechanisms work without our heads exploding. In the future if you ever want to go beyond any tutorial consider diving into these topics:


Hi everyone!! thank you so much for your help! I did manage to get it working but I basically changed the entire way that the code functions.

For anyone that is interested or is having similar issues i’ll explain it a little here. i read up on using an integer input parameter for my interface function so thats what i did in the end. in my the interface where my elevatorMove function was held, i create an integer input parameter i named floorNumber. I then also created a integer variable in my original button blueprint also called floorNumber.

in my elevator blueprint i ran a “for each loop” node that got all the child actors of the evevator. i casted it to the floorbutton blueprint which i then plugged into setting the floornumber variable from the floorbutton blueprint. i also made sure to attach the array index from the “for each loop” to my floor number so that for each instance of the button the variable assigned would increment by 1. I ran this at the start of the game by attaching the beginplay event to the for each loop node, so that the buttons would set their numbers instantly.

this way when I click on a button it returns the floornumber, it got set as, back to the floorbutton blueprint, where you get the floorbutton variable and plug it into the floornumber parameter of elevatorMove I was calling. this way it feeds the number through the interface function and can return the value back in the elevator move event in the elevator blueprint.

from there I dragged the floor number to an equal node. where you can check if A is equal to B, and if it is then execute the code, if not check if the next “equal” node matches. so if the button i interacted with returned a value of 3, then it would run the code outputted from the branch that had the equal node matched to 3 attached to it.

i suck at explaining things so sorry if its a bit confusing. hope this helps anyone who gets stuck with a similar issue, and thank you everyone for helping me learn a little bit more about coding!! <3

edit: i already had an interact function which used a sphere trace to see what im looking at, and what is interactable. was the main reason i decided to scrap the original since i already had something detecting what i was hitting :slight_smile:

1 Like

Can you hook up a print string to “Cast to BP_Player” on “Cast failed” and see if maybe the code stops there…

Edit: I see and missread about the debug lines from the line trace. How about removing the “Do once” node and test if the code executes without it. Awso the make array i think you could remove it and test.

You could still put print strings after each of your tags / branches after them on true and false and see what fires