Drag and Drop Material

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.