How to swap material using widget?

If your blueprint unique (only 1 object of sofa and others), then on LMB click(or else) create linetrace action from camera to object, then check what object it is and call widget you need. You can just create widget if your blueprint unique, or give to widget this object.

Then in widget: on every button create event onClick - and from your blueprint object get your mesh, call “Set Material” node, and for material pass material you want. If your blueprint unique, you can get your object by “Get all actors from class”, and getting 0 index of array.

If you didn’t undestand something, feel free to write me :slight_smile:

I have an interior project. I am using unreal studio to create interactive presentation to the client. So far I have completed final light built and game play was quite smooth. Now I have to give at least 3 material option for each objects like sofa, floor and the kitchen cabinets.

For testing, I have taken a box,a sphere and I have converted those components into blue print class. created 2 widgets for the 2 components,3 materials for each component. Now I have to create an event, when the game play begins clickon objects with mouse cursor call for create widgets and click on the widget change the materials. Please suggest me to create blue prints for this.

I am adding the game and exported sequences also for better understanding.
Link Gamemode Seq - YouTube

By the way, “unique” way is bad practice, so i’m gonna show other one:

  1. Line trace and widget creation posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4 - This is for linetrace and creation widget. Should be in your spectator or character. Those widgets should be for sofa and for floor, not the same. To make this “Actor” pin, go in widget, create new variable with “Actor” type(or sofa or floor), and check “Editable” and “Expose on spawn” checkboxes.
  2. Material change on button posted by anonymous | blueprintUE | PasteBin For Unreal Engine 4 - This is for your widgets. Every button “OnClick” event - Click on button in viewport, and then in Details → Events create this new event.

Hi SpynderYT,
Thank you for your reply.

the sofa is one object and the Floor is one object. One widget for Sofa and another widget for Floor.I have created Onclick buttons for the widgets. The issue is Begin here. I don’t know how to create triggers to execute widgets.

Thank you SpynderYT,
Actually I am not that good in BPs, Could you please tell me step by step.
For Easy Understanding I have created new scene having sphere, Box, Cylinder. and Converted them in to select actor to blueprints. 3 widgets and 3 material instances for each object.

Opened level blueprint and pasted the Script. I got some errors,please have a look

for what i can see right now - It should be done in your character, not map blueprint. If you don’t have one, it probably better to see tutorial, there’s a lot to be said. In character BP will be camera(should be), it should automatically connect. Get controller will also connect. For the widgets and red pin, how i said before: create new variable with “Actor” type(or sofa or floor), and check “Editable” and “Expose on spawn” checkboxes. Instruction on screenshot: http://prntscr.com/orrz19. Everything else looks fine, except for you have to connect “Actor” on Fabric Widget.

Hey,
You could try something like this.
Run a LineTrace and when hit something save hit result as variable (you will need it later). Check class of actor hit, if it’s the right one then create widget, or bring it up on screen if created earlier (is valid check). Set game mode to UI and bring up mouse cursor on the screen. If you want to check more item (classes) do another check of the first branch false.
Rest should be pretty clear with the screenshots if not just ask.

Comment due to attachment limit.

My actual widget.

Hey SpynderMK
I have done in my First person camera still not working, it seems complicated.
In Fact I am not looking for line tracer. I just want a clickon the object(trigger) to open the widget.
we have to swap the material with the widget.

Any way thank you for your patience for guiding me.

Hey DonBusso.
I have done in my First person camera still not working, it seems complicated.
In Fact I am not looking for line tracer. I just want a clickon the object(trigger) to open the widget.
we have to swap the material with the widget.

I have tried your way, when I reach the 2nd screen shot set function (show cursor), Not able find.
Any way thank you for your patience for guiding me.

well you can’t just “click” on object, you have to tell the game what are you want, and line trace simply makes a line from your point of view to forward, getting your object. Maybe this tutorial about linetrace could help you: Unreal Engine 4 - Line Trace Basics - YouTube

yes, I think this could help me.

I will try that now.

thank you.

I am looking some thing like this…But I am not understanding the language

Can you explain or show me which part doesn’t work for you. If you don’t want to use trace then how do you plan on recording the hit? I think this is the easy way of doing it but if you have something else in mind, let me know.

To get set show mouse cursor node you need to untick content sensitive or drag out from player controller and then call cursor setter. This node had to be connected to player controller or it won’t work.

Did you see the gif images? This is exactly what’s happening, material is getting change when you click on the button inside a widget.

Here’s the link again

i think he’s doing the same thing i described. If you really want use this, simply copy the code from his video. Try to make the line trace, and go from it.

Hi DonBosso,
Please find the image.
I have taken first person game and I wrote this script in the camera blue print.
From branch node I am not able find set variable(Image 2). I am getting stuck in that stage.

285150-first-person-level-blue-print4.jpg

You have to create new variable from this. Drag the pin “Hit” from linetrace and at the top(i believe) and stop it at empty space on the grid. There will be button “Create variable”, then you’ll have to name it.

Remember that every output (stuff on the right hand side of the node) can always be made a variable.