7.Multiplayer Setup & player starting camp

10.Produce Units From Buildings



Make Units showed in Building selected widgets

image.png

Create a widget, called Produce unit 1 widget
Change to custom on screen
image.png
Add button and image (add unit 1 image in brush) layers, set widget padding as 3
image.png
go to graph, add on click event on the button,
add variable building Reference
image.png

Add function in RTS interface with 2 inputs
image.png

Back to Produce unit 1 widget
image.png
Duplicate the widget, name as unit 2 widget (and so on for more units)
Replace the image and event graph produce unit to unit 2:
image.png

Go to Parent Building class, event graph, add action box variable:
image.png
extend nodes at end of Create building selected widget commands:
image.png

Go to First Building BP, event graph set
for create widget unit 1, then unit 2, thn begin play parent:
image.png

Set action in the unit box:


Go to PlayerController, event graph,
add event produce unit and custom event node: Server Add Unit to Queue (set the details setting):
image.png

Go to Parent Building Class, custom event: Add Unit to Queue:
image.png
Add a new variable, replicated:
image.png
Still in Parent Building Class, drag the new variable:
image.png

To deal with actual production of the unit itself, add pin on event begin play sequence:
default value on production timer graularity
image.png
Continue :
image.png
(set Timer by event node, tick Looping, or else won’t produce any unit upon clicking on action box)
image.png

Introduce a time needed to produce the unit:


Go to Parent unit class, add variable:
image.png
Go to Unit Style 1 BP, set production time e.g. 4
image.png
repeat the same on unit style 2

Back to Parent Building Class, graph:
image.png
For branch true side:
image.png
Add a variable:
image.png
Promote variable from divide node, set the production progress variable as replicated:
image.png

Add a box collision component, called Unit Spawn Point (a location where unit will be produced)
scale it down to 0.2 on xyz
image.png
Go to First building BP, the unit spawn point is inherited here from the parent class
drag the point a bit out of the mesh:
image.png
Back to Parent Building Class, set the following graph after SET production progress node:
image.png
Overall:
image.png

Go to Player Controller, event graph, complete custom event node with Add unit to Queue (created in Parent Building class as custom event):
image.png

Go to Building selected widget (bind values to producing building):
On Unit Production Image layer, Create bind on Brush
image.png
image.png
In progress bar layer, bind Percent:
image.png
image.png
On Unit production image 1 layer, bind the brush again:
image.png
copy highlight nodes above, repeat on image 2 and 3 layer graphs
Change is valid index and get nodes value to 1 in image 2, 2 to image 3, return value image size 50x50
image.png
image.png
To control visibility of “Text +” layer, go to graph:
open GetVisbility_0 funciton, add follow highlighted nodes:
image.png
Copy and paste the highlighted nodes on function Get unit production image 1 visibility:
image.png
Repeat the same on image 2 and 3 visibility functions, but change is valid index to 1 on image 2, 2 on image 3:
image.png

Back to Parent Building Class, replicate on Unit Being Produced variable:
image.png
(To let show the unit production image when producing unit as a client)
image.png

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.