Skip to content

Unit Selection

Jesus Bracho edited this page Jan 11, 2024 · 4 revisions

Unit selection is a bit of functionality unrelated to the camera, but since they often go together I added an implementation here for convenience.

  1. Add the RTSSelector component to your Player Controller class.

image

This component provides access to an array of Selected Actors which you can use to implement unit orders.

image

  1. In order to populate those selected actors we need to make use of the HUD. In the future I'd like to make this more composable, but HUD classes don't support component classes so for the time being I've provided a new HUD class. You'll want to create your own blueprint class as the RTSHUD class has plenty of hooks which can be overridden.

image

  1. Finally, in order to make actors in the scene selectable, their blueprints need to have an RTSSelectable component. You will also want to create your own blueprint class as this is how we customize the feedback when a unit is selected.

image

  1. In your own RTSSelectable-derived blueprint, we can set up some quick and dirty feedbacks by overriding the On Selected and On Deselected events.

image

image

  1. Add this custom blueprint to an actor in the scene.

image

  1. Now drag-select the character, and the On Selection event should fire (it might be a little tricky to catch them if you're using the Top Down starter package like I am).

image

image

  1. This is quite boring of course, so let's set up a unit highlighting system found in lots of traditional RTS games. First, start by adding a Decal component to the actor class containing your selectable component.

image

  1. Resize the decal to be facing down and near the actor's feet.

image

  1. I've included an example material M_UnitSelection for convenience.

image

  1. Set the default visibility of the decal to be false.

image

  1. Now, in your selectable blueprint, update the On Selected and On Deselected events to the following to toggle the visibility of the Decal component. That should do it!

image

image

Clone this wiki locally