RTS Multiplayer Game Series

6.Add selectable Buildings



Add a BP actor, called Parent Building Class
Add building mesh (untick receive decals),
Selected Decal (change decal mat, size 100, rotate -90m location -10, and untick visible in rendering)
image.png
image.png

R click the parent building class to create child BP class, name as First Building
Change the mesh in First building, drag it in scene

Go to RTS Interface,
Rename Select unit and de select unit as select this and de select this
image.png

Back to Parent building class, class setting, add RTS interface
In event graph:
image.png

Go to Parent Unit Class graph, update and replace the event (de)select this nodes:
image.png
Double check RTS Marquee HUD too, see if anything not complied, after rename RTS interface from “unit” to “this”

Open Player Controller:
Left mouse button event node, modify between Marquee Pressed message node
(add actor variable selectedbuilding)
Collapse a marcos for selected nodes, name as HandeBuildingClick
image.png
Final looks as:
image.png

Now the building can be selected. To de-select it:


Go to RTS interface, add new function for clearing:
image.png
Go to Player Controller, create events for the clearing:
image.png
Go into Handle Building Click Marco just created, add the follow (to clear anything before selected input):
image.png
Marquee selection created in previous lesson has to be activated by connect false branch to output:
image.png

Optional:
For RTS game normally don’t want be able to select both characters and the buildings, now it is possible to do so coz after select the building, rectangle selection function can still be used to select character:
image.png
To solve this:
Go to Marquee HUD graph, Get Actors in Selection Rectangle node (in Check for Actors under the Rectangle Command)
Change class filter from actor to parent unit class
image.png
Then in Select units under rectangle command, add clear selected unit
image.png

Now if select the building, then use rectangle to select unit character, the building will be automatically deselected

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.