Adding Child Widget based on hit actor/component

Very Noob (about a week really working with UE)

For about 3 days I have been trying to update the content of a pause widget based on the actor hit by a trace. I currently have a setup that channel traces for specific actors, highlights them when they’re centered in the viewport and brings up a pause menu on “InputActionFire”. That all works great.

I would like to be able to create levels with many different actors that when selected as mentioned above, change the contents of the widget. There should be a way to do this dynamically without hardcoding/blueprinting each widget and detecting with branches from the character blueprint. What if i have 50+ meshes?

My thought process was:

  1. create blueprint from static actor mesh
  2. Somehow link it to a dedicated widget blueprint that contains buttons/elements specific to that actor
  3. add that widget as a child to the pause menu widget

I have tried this in so many ways, but can’t get it to work. Maybe i am going about this all wrong.
Pictures explain better I think.

TLDR note: I am trying to make a material changer here, and a similar workflow will also apply to swapping full meshes (haven’t tried this yet, but should be a bit easier). I know some exist out there already, but im trying to set myself up for a proper workflow when creating future levels after main functionality release.

Thanks. This engine is awesome.

in characterbp+gameplay.jpg: if its not valid you are trying to set Selected Object into a widget that doesnt exists, and even if it worked, you are setting a new widget reference, so the value you were setting would be lost.
why dont you just create a struct with 2 members, 1 is the mesh, other is the widget, and then make it an array?

Clever, didn’t know much about structures. So now i can get the object and it’s associated widget, but can’t pass it to the Pause widget.

I am totally missing something and i am fried.

Maybe i don’t understand casting, i think i have to cast something to make this work. So i set the dynamically created widget to a variable, and want to get it on pause menu construct. I know this seems like such an easy task, but i am trying to learn, and after searching all over am having trouble finding good references to do what i want to do.

Sorry, i commented on my own question instead of your answer.

not 100% sure what you need but i tried to do what i thought it was. i “may” have overdone it a little, and note that this is not polished, but its more like a proof of concept.

DISCLAMER: i dont like the method of creating a “studio” (you will below a link explaining using a studio to render a 3d image to a widget) and having it floating around, but right now i think its the only way.

LineTrace logic:

  • Hit the actor with a LineTrace.
  • HUDClass has an array of valid actor classes and will compare the class of the hit actor to it.
  • If its a valid class, get the actor and do an interface call,you dont need to cast for this
  • The Actor will send its data stored in a MeshData (struct) variable inside the actor blueprint to my HUDClass. then HUDClass will create a “Studio”, its widget (will be child of a widget containing all the meshes) and update everything it in the struct. Finally it will update its own list (Created Widgets) . then return the updated MeshData and re-store it in the actor blueprint.
  • Finish the trace with Updating the parent widget (if it has been created, dont get confused, as we havent created the parent widget yet, only the children)

PauseMenu logic:

  • Call pause menu event on HUDclass
  • HUDclass has a variable of type w_PauseMenu. if its valid (already created) request update widgets (might not be needed for you, since its on pause, for me, it was a floating menu so i could re-hit other actors with the menu up)
  • UpdateMenu checks if theres a widget in the array of MeshData that is not a child of the Horizontal box (container of all the widgets), if there is, creates a child.

first i understand you need to display the mesh into the pause menu right? not certain how was your approach but i chose this methods (i used the first cause it was the first i found, also, for having multiple “studios” you actually need walls, or you will capture multiple objects)

right now unreal dont have (i think) a built in way to make materials from mesh, so this is the closest i could get.

So now we have a studio that feeds a material (in my screenshots its CapturedMaterial). You will need this to create the instances, will work as a template. The Render Target created in the first link is needed just to make it work, even if we are replacing it (see last part of Widgets.jpg), the material wont work if its empty.
After that i made 2 widgets, one that will be the parent of the created widgets. (Widgets.jpg)

For my test purposes, i made 2 blueprint actors, BP_Sphere and BP_Cube. also, i made a struct ST_Meshdata (StructInterface.jpg). ActorReference is not used in my example but it could be used as a reference to the future. i also made an interface (StructInterface.jpg) because if you are hitting an Actor, you are not gonna cast for every single actor you have and find out which is the correct one and then call for a function.

On the HUDclass, i implement the CreateActorWidget, ShowPauseMenu, AddMeshData, RequestUpdate and CheckValidItem (HUDClass.jpg)

After that, we are only missing how to call this functions, i implement E key to make the linetrace and U key to bring the menu (LineTraceShowPause.jpg)