I currently have a line trace system where if it intersects a BP actor it displays a widget saying “[F] to interact”. I was wondering how I would call the static mesh of the BP actor and display it in the widget per object rather than just the pre written “[F] to interact”.
Plain text works too, just with my line trace I want the widget to be updated with the name of the object itself. Could I do this by somehow calling a bind variable from the widget BP to my line trace BP?
I’m very new to UE5 so I’m not sure how to call variables from other BP’s.
I believe trace returns a FHitResult struct which includes a reference to the hit actor. From there you can use get component by class and find the static mesh and then you can get the name from the mesh reference. You can also as Everynone mentioned make an interface with a single function that returns the name on your actor, cast the hit actor from trace to your interface, call that function and use the value for your widget
Since this can be done in too many ways, we’d need to know how you’re handling things at the moment in order to suggest something that fits right into your existing system.
As you can see I had to assume a lot since we know squat about your setup.
Disclaimer: the above can be set up much better - it all really depends on the features and behaviours you need.
Also, here’s a link to a slightly more nuanced behaviour:
Here, each interactive actor has its own widget. There is a project link in the second post - consider taking it apart to see how it works. Should work fine in UE5 once updated.
The way that I am doing the line trace is similar to yours in your BP_FirstPersonCharacter, but my line trace is a function called “Trace” in an actor component called “AC_interactionTrace” Then the “AC_interactionTrace” is pulled in a function called “Setup Interaction Trace” in the “BP_ThirdPersonCharachter” which checks that the trace is a locally controlled pawn.
I think my question is, where would I setup the area to place a widget bind variable? In my Trace function in the AC_interactionTrace, the Setup Interaction Trace in the BP_ThirdPersonCharachter, or another location?
I would’ve posted more screenshots but some reason i’m limited to only one media per post.
variable property binding is in the widget itself, as seen is my example
create a widget either in the component you use for tracing or the player BP, reference it - on Begin Play is fine
when the trace connects, set the widget’s bound text variable using the widget’s reference
Ideally, you wouldn’t use property binding which executes every frame and use an event driven approach but polling a variable for this is more than OK.