# Drag and Drop Material

**URL:** <https://forums.unrealengine.com/t/drag-and-drop-material/458600>\
**Category:** Rendering\
**Tags:** drag-and-drop, unreal-engine, question\
**Created:** [November 19, 2019, 1:20pm UTC](https://forums.unrealengine.com/t/drag-and-drop-material/458600 "2019-11-19T13:20:14Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Supline](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Supline](https://forums.unrealengine.com/u/Supline)\
**Post date:** [November 19, 2019, 1:20pm UTC](https://forums.unrealengine.com/t/drag-and-drop-material/458600/1 "2019-11-19T13:20:14Z")

</div>

Hey, is there any tutorial/marketplace item or any way to do drag and drop material as a player (Front end) for to change the material of the object.

Thank you!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [November 19, 2019, 3:33pm UTC](https://forums.unrealengine.com/t/drag-and-drop-material/458600/2 "2019-11-19T15:33:54Z")

</div>

Can’t think of a tutorial but that shouldn’t be difficult to create. How would it work? Drag & drop a tile from a UI onto a world object?

Or something more complex?

---

<div class="post-metadata">

**Author:** ![Supline](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Supline](https://forums.unrealengine.com/u/Supline)\
**Post date:** [November 19, 2019, 3:35pm UTC](https://forums.unrealengine.com/t/drag-and-drop-material/458600/3 "2019-11-19T15:35:33Z")

</div>

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/a/b/6abf12f53ed0e584f0508c7f314e83e3fa0e8a5b.jpeg "House Design and Plan With Blueprint - Unreal Engine 4") ](https://www.youtube.com/watch?v=ZtfelOFLMEM)

For example like this, 0:44 second

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [November 19, 2019, 5:46pm UTC](https://forums.unrealengine.com/t/drag-and-drop-material/458600/4 "2019-11-19T17:46:41Z")

</div>

The below assumes you know how to drag and drop and handle widgets, it’s not a tutorial, just a method:

* * *

I got it to work pretty quickly by creating a custom drag & drop OPeration. When dragging, create the OP as usual but since we are using a custom OP, you can have it dispatch data - this is bound to a custom event in the Player Controller - this is necessary because the OP itself cannot access the player controller. We’re sending the material and the mouse coords:

 ![292641-dragdetect.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/6/2/56243b7b0c3daea544cad076150679bccb087300.png)

When the player drags the widget and drops it in the world where no other widgets are present, the OP gets Cancelled and the below script is called. The payload is the material, and mouse screen position is sent through a dispatcher to the Player Controller - this is necessary as the Player Controller has no idea where the mouse cursor is during drag:

 ![292620-customdragdrop.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/9/b/19b666004e181039430ff3b109836720dba16a7b.png)

When the player controller receives the dispatched call, it converts the mouse screen coords to the viewport coords, line traces in the scene and applies the payload (material) to any component hit.

 ![292642-playercontrollerdrop.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/6/7/967c102e75b3a0d5a23c59c29b0f04f809d3a8bb.png)

* * *

[![Image from Gyazo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/9/9/199944458648fcab5351dbd36de1510fde88c9d8.gif)](https://gyazo.com/26173b8551200acd41d3f6c23cfbb5aa)

* * *

Now, this is _a super rough quickie_ and can be improved A LOT. The biggest gripe here is that we’re using a material in the UI domain - you definitely do not want to do that for arch vis ( or anything that’s not UI ;p ).

Use a texture in the UI and use that texture as a parameter when creating a dynamic material for the world objects.

---

<div class="post-metadata">

**Author:** ![someonelsee1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/someonelsee1/32/566470_2.png) [@someonelsee1](https://forums.unrealengine.com/u/someonelsee1)\
**Post date:** [August 30, 2022, 9:08am UTC](https://forums.unrealengine.com/t/drag-and-drop-material/458600/6 "2022-08-30T09:08:56Z")

</div>

@Everynone Hi, this topic is pretty old now but I’m looking to do the thing you explained, set a material from a widget to an actor in the viewport but I can’t achieve it, is it possible you show how you did it on video ? I’m pretty new to this kind of things and I really need this feature in my project!

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 30, 2022, 9:50am UTC](https://forums.unrealengine.com/t/drag-and-drop-material/458600/7 "2022-08-30T09:50:06Z")

</div>

The script is in the post above. Which part are you having an issue replicating?

---

<div class="post-metadata">

**Author:** ![someonelsee1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/someonelsee1/32/566470_2.png) [@someonelsee1](https://forums.unrealengine.com/u/someonelsee1)\
**Post date:** [August 30, 2022, 12:34pm UTC](https://forums.unrealengine.com/t/drag-and-drop-material/458600/8 "2022-08-30T12:34:09Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/b/1/fb15c06ae56b71668c829adf37601a73df092d73.png)  
This part, I don’t understand how you did it

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [August 30, 2022, 1:57pm UTC](https://forums.unrealengine.com/t/drag-and-drop-material/458600/9 "2022-08-30T13:57:22Z")

</div>

Look into how drag & drop operation works, you can create your own and add an Event Diapatcher - plenty of tutorials on those.

Once the custom drag and drop has an Event Dispatcher, you can register it with a Custom event in the Player Controller.

---

<div class="post-metadata">

**Author:** ![someonelsee1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/someonelsee1/32/566470_2.png) [@someonelsee1](https://forums.unrealengine.com/u/someonelsee1)\
**Post date:** [September 1, 2022, 8:54am UTC](https://forums.unrealengine.com/t/drag-and-drop-material/458600/10 "2022-09-01T08:54:40Z")

</div>

Well, I managed to understand and replicate what you had done (partly), I just have three questions:

- I can’t connect the Bind Event target to my drag & drop op, it says that it’s not compatible  

- What’s in your Payload variable here ? Where does it come from ?  

- The OnDragDetected and EventOnDragCancelled are on the same Widget Blueprint right ?

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 1, 2022, 11:12am UTC](https://forums.unrealengine.com/t/drag-and-drop-material/458600/11 "2022-09-01T11:12:56Z")

</div>

Avoid dropping nodes on their own and then connecting wires. Drag wires first and then _search_ with the Context Sensitive filter on.

It’s not compatible because the drag & operation does not have the required dispatcher. Looks like you’re using the default one at a glance - judging by the drop-down class selector.

* * *

`Payload` is a part of the drag & drop operation - it is the very data we’re dragging. In one of the images above you can see the material being piped in as `Payload`. When you `OnDrop` or `OnDragCancelled` a widget, you get access to the operation that handled said _payload_.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/f/b/efb7e3042f96df739ca40d0e17982e2e0867cd8d.png)

In this very case, if we handle `OnDragCancelled` in the drag operation itself, you get direct access to the `Payload` since it’s inherited:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/2/a/e2a80f49d6183ad6c4b4bf854b1faf57d00d22a5.png)

So just drag it to the graph. Or just search for it with Context Sensitive on in the drag operation blueprint.

* * *

> The OnDragDetected and EventOnDragCancelled are on the same Widget Blueprint right

Depends on the required implementation. `OnDragDetected` should be in the widget the mouse is interacting with - _usually_ the widget that we want to drag, but it’s not a must.

`EventOnDragCancelled` will be _usually_ in the drag operation (it is here). When I attach screenshots, the widgets the script belongs to are usually captured as well (see arrows):

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/b/0/1b03a55f778bf3e37f69129167ba05f9dbb6c541.jpeg)

But any widget can implement `EventOnDragCancelled`. This gives us a chance to perform an action in case we drop something where it does not belong, for example. Or handle edge case scenarios where a drag operation is terminated unexpectedly.

---

<div class="post-metadata">

**Author:** ![someonelsee1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/someonelsee1/32/566470_2.png) [@someonelsee1](https://forums.unrealengine.com/u/someonelsee1)\
**Post date:** [September 2, 2022, 8:54am UTC](https://forums.unrealengine.com/t/drag-and-drop-material/458600/12 "2022-09-02T08:54:21Z")

</div>

I can’t thank you enough for the time you took to answer my questions! It works, and now I understand more what I’m doing.

If I can bother you one last time, can you explain the process of what you said below in a bit more detail ?

> [@Everynone](#):
>
> Use a texture in the UI and use that texture as a parameter when creating a dynamic material for the world objects.

---

<div class="post-metadata">

**Author:** ![someonelsee1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/someonelsee1/32/566470_2.png) [@someonelsee1](https://forums.unrealengine.com/u/someonelsee1)\
**Post date:** [September 7, 2022, 9:00am UTC](https://forums.unrealengine.com/t/drag-and-drop-material/458600/14 "2022-09-07T09:00:43Z")

</div>

Nevermind I managed to do it myself. Thank you again!

---

<div class="post-metadata">

**Author:** ![Mr\_Crush](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Mr\_Crush](https://forums.unrealengine.com/u/Mr_Crush)\
**Post date:** [December 19, 2023, 7:51am UTC](https://forums.unrealengine.com/t/drag-and-drop-material/458600/16 "2023-12-19T07:51:17Z")

</div>

@Everynone i have got an error while binding [Create Event : missing a function/event name.] but i already created the custom event in my character bluprint

 ![error](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/a/b/eab063746cc0e1b15587d4069d8d24de821a1880.png)  
 ![eroor12](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/1/a/51a22c5044edabaf2b3015f3098d5db5da112e76.png)  
 ![error123](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/4/7/3470245069ad8d3c0f62f773eac3d24f49abfff9.png)

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [December 19, 2023, 9:14am UTC](https://forums.unrealengine.com/t/drag-and-drop-material/458600/17 "2023-12-19T09:14:18Z")

</div>

But you did not select it from the dropdown in the 1st pic.

Also, in the 3rd image. Why is it called P **l** ayload? You need use the variable declared in the Drag & Drop OP class. It already exists.

It seems you’ve created a null var of the MID type which, #1 - does not need casting (blue note) and #2 - will never works since it’s null.
