Drag and Drop a material

Hi everyone,

I’ve been having a lot of trouble figuring this out, I wanted to see if anyone here has a solution…

I’m NOT advanced at Unreal Engine, so I’m using blueprints, instead of code, and also have been working with Unreal for just about 2 months on my own.

I’m creating a “Sampler” for carpets and floor tiles and such. So you have Top-Down view of a floor plan, and the floor is separated in “areas” of how you can add different materials to the floor (ex. Kitchen, Living Room, Bathroom, etc). The idea is for the user to drag and drop a material (HUD UI button) on top of the Kitchen for example, and the kitchen floor to change to that material. the same for the other areas of the room.

This whole app if for the iPad, although I’m working with mouse and keyboard right now.
So this is what I’ve tried:

  • Line trace to the mouse position converted to World Space

  • Object type to create a “Make Array” where I created a collision object and only the floor geometry is in it (to ignore the rest of the geometry, incase there are tables and chairs or other furniture)

  • Break Hit Result the face Index and the Component to a “Get Material From Collision Face Index”, Section Index to a Set Material Element Index and the Hit Component to the Target of same Set Material.

I have also tried:

  • Creating a Function in the Controller that will give me the Index # of whatever I’m hitting with a Line Trace, and using that function as a trigger for the button to set a material. (Basically that was the idea, but was poorly developed) so I never even got cose to ir, mostly because I’m still having trouble referencing the Mesh as the Target of the Set Material in Widget Blueprints.

The Way I figure should be done (Even though I don’t know how, or if its even possible) is:

  • Create a Function that will Give you two outputs (Both things needed for the Set Material Node)

    • a hit result of (whatever you have under your finger, Screen Space to World Space of something like that) the Face Index, this will give you the ‘target’ element index of the material you want to change.

    • A hit result of the component, the ‘target’

  • Create a Custom Event Dispatcher to trigger that function (Or Macro) and set the outputs to the Set Material fora each of the materials you have (Material_01, Material_02, etc). This should allow you to click the button and drag, and while dragging, the line trace will give you the target mesh and the element index it has (the one you will change) and when ‘released’ or ‘Dropped’ it will trigger the Set Material, Target and Element Index being the return values of the Hit Break Result while dragging.

  • Call the Event Dispatcher with the button in the Widget Blueprint.

Please Help,

Any help is appreciated,
Thank you in advance!

Best Regards!

Hopefully I dont confuse you more.

Make an array of the different materials they can use. (You can make arrays of almost anything in UE4)

Figure out how u want to select the new material. Get index number from that array. Have a duplicate array on the selected object. On that mesh set material and use the integer from the array. I would probably use a blueprint interface in there with a simple function call that passes the array integer as an input/output. I use blueprint interfaces for ALOT of interactions between.

P.S. I dont know if you only need to set the material on one face of the mesh. That may or may not be possible, I don’t actually know. May have to get creative.

Thank You!!

I will try to do your solution, at first I did wanted to add the material to only one area of the Mesh (That mesh is divided from 3dMax with different materials) so thats why I wanted the index No., so the Set Material will affect that selected index.

I’ll let you know what happens by trying your solution!

Best Regards!

I think if the mesh already has different materials (or material division areas) you should be able to change the material for one section somehow.

Hi again,

Sorry if this question is stupid, but. When you said have a “duplicate array on the selected object” is there a way of duplicating an array variable to another blueprint? o just re-create the same one with the same list of materials?

I have the Material Array on the controller, that also where I cast the HUD where the materials “menu” will be. I did the function in the Interface with an Array Input and an Array Output, I was about to do the array inside the object, but not sure if I should redo it using the same order. After that I would just have to find a way of doing the Drag and Drop so the “drag” would select the material (index from array) and “drop” would be the target (Index that would replace) correct?

Sorry if this questions are kinda dumb, trying to get the hang of it!

Best Regards!