How to access widget after successful line trace.

I’ve made a line trace blue print that allows me to click on an object which opens my widget. See blueprints and gif below. I can then press E to escape the widget once making my changes and return to the player view.

Image from Gyazo

Now I want to make it so that I can use a tick event to have the trace looking for objects and when an object is found my widget appears and does the same thing as my previous line trace (make changes then close widget with e). However I’m having some trouble getting it to work. When the camera is in the correct distance I can’t change my textures etc. But if i step out of the distance I can. I have another gif below demonstrating what happens as well as the blueprints.
Image from Gyazo

Any help solving this issue would be greatly appreciated. Essentially what I’m trying to create is an app where you can move to an object have a cue that the object is changeable and then be able to change the object and its materials.

Unlike mouse button press Tick fires every frame - you’re creating 60 widgets per seconds (or more!). Once you step out of range, you stop creating widgets over and over again and are finally able to interact with the last one added to the viewport - the one on top.


Consider the following:

After creating the widget, store its reference (right click Return ValuePromote to Variable). During Tick, check if the widget reference is valid; if it is, it means the widget already exists and rather than creating a new one, make sure it’s just visible. This also allows you to later on remove just this one widget rather than the entire user interface, which may not be a good idea once you have other elements on the screen.

Depending on how you’re planning to expand the project later on, you will (most likely) need a slightly different approach to communication in order to handle the growing complexity of object interaction.

I am assuming here you’ll have more than a bench and floor to interact with.

Hi, thanks so much for the reply I’ve been pulling my hair out trying to make this work. The top half of your post has opened my eyes a bit in terms of what is going wrong but I’m still struggling to make sense of the bottom half. Apologies in advance for my ignorance but this is my first time trying to program in Unreal. Normally I’m an artist. But I’ve been tasked with this particular job and am desperate to make it work.

I assumed due to your screen shot that all of this takes place before connecting to the line trace? I had a quick attempt at replicating what you have above but it just creates the widget at the start of run time. Maybe if I explain what I’m trying to do a bit more it may help. I’m creating an Arch Vis scene of an apartment, the goal is to be able to walk around first person. When walking up to objects Chairs, benches, floors, etc when at the correct distance the cursor changes to indicate that the objects are interactive. Then once you click the object the widget appears which allows you change the object type and texture type. Once your happy with your selections you can move on around the apartment in 1st person. This video is very similar to what i’m hoping to achieve
Unreal Engine 4 Country House - G3258@4.4 / EVGA GTX 750 Ti FTW - YouTube

This is the blueprints after taking into consideration what you said:

Image from Gyazo

In the second screenshot it looks like you’re still creating widgets after the line trace. However, since you mentioned arch vis, may I suggest a slightly different approach.


Let the player character create a single widget on Begin Play only and store its reference, keep the widget hidden - this way you no longer need to create / remove any additional widgets. Instead we’ll wire this one widget to interact with the objects in the scene and show / hide it as needed.

This is my widget:

It has a custom event that accepts any object the trace can interact with. The widget can store and clear a reference to any object in the scene via a cast. And its button can use that reference to change mesh / material and so on.

The Player’s line trace would look like this:

It shows / hides the widget and sends it the object the trace hits.

And the end result:

Image from Gyazo

This setup can be massively improved by using more advanced communication techniques like dispatchers or interfaces (if you need a lot of class to class interaction). But even with this method you should be able to grow the project a bit without creating a massive wire spaghetti.

Do tell if something makes little sense here.

So I’ve tried to set it up in the current scene I have so there may be some issues left over that I haven’t adjusted. It seems as though when i walk to the box the widget appears and when i leave it goes which is great. But I can’t interact with it.
Image from Gyazo

I did notice also that you only had the first person blueprint as well as the widget blue print. And was your cast just to an actor? When i do a cast i’m casting it to the blue print I’ve set up see below maybe that’s what i need to change only thing is I’m not sure how to cast to just a mesh actor.

270928-3rdattempt-blueprint.png

I feel like I’m on the right track I just need to be able to show the cursor select the item then exit to continue on. More help would be much appreciated thank you so much for all your help so far. I’m not sure if it’s possible for you to send me your scene to have a look at at all? but thanks ether way.

In your original images you had the cursor working, I did not include this part. But it would work as you had it. Show the cursor via controller or lock the input mode as needed.

Okay so I think I’ve managed to set it up however I do have a couple more questions so sorry for the noobness and thank you so much for your help so far.

Image from Gyazo

So I am now able to walk up to an object, have the widget appear, be usable, then disappear when I move away and the trace isn’t connecting with the object anymore.

However I’d also like be able to exit the widget by pressing E so that if a player looks at the floor for example they have a way of closing the widget (you can’t walk away from the floor once looking down). Here’s my new blueprints:

Also any hints how i would apply this to multiple objects? I actually do want to have more then one widget so that each object has a unique menu. I.e. A chair might have 3 different chair meshes and three different textures. Then a table might have 3 table types and three textures. At the moment this blueprint only seems to reference one object and one widget and i’m unsure how to add more.

Thanks again.