Click multiple Actors and let them move

Hallo guys,
I want to make a game like “age of Empires”. Everything works fine.
But i want to make that you can select persons by clicking left mouse button and then let them move after clicking at a place in the world. Its a game with Top view. With One Person it works but i want that you can select a specific number of persons and then let them move together to the clicked location.
Has anyone an idea? Would be great if someone could help me with this Little Problem.

I wrote out an elaborate reply to this questing on my phone but I left it in the other room and I CBA to get it. /csb

This is a frequently asked question from RTS devs. I, too, am making an RTS so I’ll tell you what I did.

Variables:
{Boolean}: {“DragSelectInitiated”};
{Actor Reference Array}: {“DragSelectedActors”};
{Actor} with {Material} below added to the bottom: {“DragSelectBox”};
{Vector}: {“DragSelectStart”};
{Vector}: {“DragSelectEnd”}

{Material} with zero opacity and a little glow: {“DragSelectMaterial”} (You can set the channels to make it only glow where it touches terrain)

[Mouse click event]->[On press]->[Branch: {“DragSelectedInitiated”} is False]->{Sub Node 1}

{Sub Node 1}: [Get Player Controller]->[Get Hit Under Cursor By Channel]->[Break Hit]->[Hit Actor]->[Get Actor Class]->[Branch: {Class is Landscape} is True]->[Set {“DragSelectInitiated”} to True]->(Continued below)

Here’s when it gets to preference. You have the option of either waiting until the drag select is finished and creating a [Box Overlaps Actors] with the origin based on the [Average] between the start and stop of your drag select or simply spawn a box actor with an origin at the corner.

{Option 1}: On click down, store the {“DragSelectStart”} variable with your cursor-to-map vector, then on [Release], store {“DragSelectEnd”} with the current cursor-to-map vector and use [Box Overlaps Actors] with [Get Vector Array Average] as the {Origin} and the extent to be half the distance between. This is not a very accurate method, by any means.

{Option 2}: Starting from where we left off, [Spawn Actor from Class {“DragSelectBox”} with corner origin at cursor-to-map’s vector]

While dragging (before [Release] gets called and {“DragSelectInitiated”} is still True), ignore all other actions (capture mouse to only the map viewport, ignoring canvas panel actions and everything not related to drag selecting).

{Event Tick}->[Branch: {“DragSelectInitiated”} is True]->[Function to update {“DragSelectActor”}'s “extent” (or, x,y variables, whichever it is) to be your mouse-to-map’s current vector]

[Mouse Click On Release]: [Branch: {“DragSelectInitiated”} is true]->[Get Overlapping Actors node for {“DragSelectBox”}]->[Branch: {“Overlapping Actors”} pin Array Length != 0; (False: [Clear all DragSelect* variables and destroy actor instance])]->True->[ForEach node from {“Overlapping Actors”} pin]->{(Optional)[Branch: {“Sub Node 2”}]}->[Branch: {check if this entry in the array is an actor and if you own it}. This way, you only get your moveable units, excluding anything you don’t own and excluding your building actors.}->[Add {“Array Element”} pin results to {“DragSelectedActors”} array (this way, you get a list of actors you have already filtered through)]->[Completed]->[Nullify your other DragSelect* variables except for {“DragSelectedActors”} ]->[Remove/destroy {“DragSelectBox”} actor]->[Set {“DragSelectInitiated”} Boolean to False]->{[Call function to add icon buttons to your UI with reference variables to the units in {“DragSelectedActors”} ]}->[Nullify {“DragSelectActors”} Array]

{Sub Node 2}: {Optional: [Array Contains “unit” characters/actors (that you own)]; False: [Check array for buildings you own] (then, if this further branches to be false, and none of the selected units are yours, just select one unit located closest to the center of your selection box)}

Start with that and tell me how far you get.

(PS: I had this formatted better, such as trying to make all of the variables bold and putting each node on a new line to make it more readable, but the format didn’t stick, so… please bear with it.)

I will try it. Thank you. In which blueprint u did this?

Ugh… I typed out a detailed explanation of how to create a player character subcomponent hierarchy but it disappeared when I clicked Submit.

TLDR; I put it in a subcomponent that is attached to my parent actor. That parent actor has another actor inherit from them and that’s what I use for the in-game camera.

You can, yes, but I recommend putting it in your controller, if you’re planning to put it directly in the player’s blueprint. The idea behind making multiple components is to modularize the code to make it reusable in other places. ie: Creating a map editor mode in which you’re not necessarily spawning a regular player character with restrictions.

So i can Do it in my player character?

And for the dragselectbox you created a new actor?
How it looks in your Projekt?

Yes. I created an actor with a collision box and set the collision channels to not block anything-- it should just be on a custom channel that won’t trigger the Overlapping events for other actors in the game. Other wise, your units will pop on top of the box when it’s not really supposed to be there, in their eyes.

The actor I made has a material applied that simply glows where it makes contact with [Landscape] class actors.

Once you have made this actor, create an instance of it in your blueprints by using [Spawn Actor from Class]. Make sure to store this actor’s instance reference to be able to update it each tick that your CursorToWorld decal has moved. Also, you will need to use [Destroy Actor] to remove the instance, once you are done with it.

What i have to do in the Point between option2 and Event tick?

I dont know why but it dont works…
Is it possible that you can send me your blueprint screenshots that i see what i do wrong?