How to get static mesh name and input it into widget

Hello,

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”.

Have an interface return a text variable from the hit actor / component and feed it to the F widget, set the text field to that value.

Or do you mean the mesh itself rather than plain text?

2 Likes

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

2 Likes

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.

calling a bind variable

  • assuming this is what you mean in the widget:

image

  • assuming we’re using an interface:

  • assuming we’re tracing and looking at stuff:

  • assuming actors carry names we predefine ourselves:

The end result here would produce:


As you can see I had to assume a lot since we know squat about your setup. :melting_face:

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.

1 Like

Thank you for the very concise and informative help, I’ll look into this and get back!

1 Like

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.

Here’s the Setup Interaction Trace function that resides in the BP_ThirdPersonCharacter which called the AC Interaction Trace (The line trace).

  • 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.