How to make a drag-and-place UI to actor system?

I’m making a card-based RTS and wanted to use a troop-placing system similar to Clash Royale, where you hold onto a card in the UI and drag it onto the battlefield, and as it gets dragged, the card transforms into the actual troop that you can move around and place onto the battlefield. Any ideas on how to accomplish this?

Thanks in advance!

Luckily there’s actually a tutorial on this:

I ended up learning from this and creating something similar and more flexible, but this should be a good head start.

1 Like

I feel like that system might overcomplicate things when you have to transform the widget into an actor in the game. The drop function might never be called if the player actually places the troop, right?

Well, you should be able to deproject the 2D position of where you’re dropping the widget into the 3D world position. From there you just spawn the actor. I don’t know off the top of my head the exact function, but there are a lot of utilities to get the world location from the 2D screen location, and vice versa.

You’d probably want to keep checking every tick if the drop location is valid for example, and if there’s a grid, you can snap that location to a grid cell.