Drag and Drop Material

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!

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?

For example like this, 0:44 second

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:

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:

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.


Image from Gyazo


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.

@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!

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

image
This part, I don’t understand how you did it

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.

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 ?

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.

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

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):

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.

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 ?

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

1 Like

@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



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

Also, in the 3rd image. Why is it called Playload? 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.