As mentioned before, most features of the plugin are implemented by the means of components to add to your actors. Thus, for adding new units (or buildings), you'll usually create a pawn or character, and add various components, depending on the capabitilies you want the unit to have. This approach enables you to combine features just as you like, for instance having buildings that can attack or units that resources can be returned to.
- Create a new pawn or character blueprint.
- Check the Replicates flag.
- Add a static or skeletal mesh and setup its location, rotation and scale as usual.
- Setup collision (e.g. Capsule Collision) as usual. You may want to disable the collision of your mesh and rely on its capsule instead.
- Setup your animations. (If you're new to the Unreal animation system, we can readily recommend the tutorial at https://docs.unrealengine.com/latest/INT/Programming/Tutorials/FirstPersonShooter/4/index.html)
- Add an
RTSNameComponent
and set its localized name if you want to show it in any kind of ingame UI. - Add an
RTSDescriptionComponent
and set its localized text if you want to show it in any kind of ingame UI. - Add an
RTSPortraitComponent
and set its portrait if you want to show it in any kind of ingame UI. - Add an
RTSSelectableComponent
, and set its selection circle material (e.g. toM_RTSSelectionCircle
) and selection sound. - If the selection order of your actors matters (e.g. for grouping in your UI), set the Selection Priority as well. Untick Receives Decals on the static or skeletal mesh to prevent adjacent decals rendering on the unit when in close proximity to other selected units.
- In case you got special visual effects for highlighting hovered actors, you can listen for the
OnHovered
andOnUnhovered
events of the component. - Add an
RTSOwnerComponent
. This will be used to store (and replicate) the owner of the unit for all players (e.g. for showing team colors). - Add your
RTSHoveredActorWidgetComponent
(see User Interface).
- Add a movement component (e.g.
FloatingPawnMovement
orCharacterMovement
) and set up its speed properties as usual. The plugin also ships with aRTSPawnMovementComponent
that basically just adds rotation updates to the built-inFloatingPawnMovement
.
- Add the
RTSVision
component to your units and set their Sight Radius (e.g. 1000). - If your actor should be able to ignore height levels for vision (e.g. watchtowers), check Ignore Height Levels.
- Add a
RTSVisible
component to your actor. That component will manage vibility of that actor, in case multiple effects want to show/hide it (e.g. fog of war, containers).
As mentioned before, units are not directly possessed by player controllers in the plugin. Instead, every unit is possessed by an AIController that will carry out orders issued by the players.
- Set the pawn AI controller class to your
RTSPawnAIController
. - Ensure Pawn > Auto Possess AI is set to Placed in World or Spawned.
- Add the
RTSGameplayTagsComponent
and add theStatus.Permanent.CanBeAttacked
tag to theRTSGameplayTagsComponent
to any actors that can be attacked. - Set the Maximum Health of the
RTSHealthComponent
. - In case your actor should regenerate health, check Regenerate Health and set the Health Regeneration Rate.
- If you want to play animations or visual effects when the actor dies, set Actor Death Type to Stop Gameplay. In that case, you're responsible of destroying the actor yourself as soon as all of your visual clues have finished playing.
- Set the Death Sound to the sound cue to play when the actor is killed.
- Add your
RTSHealthBarWidgetComponent
(see User Interface). - Add the
RTSAttackComponent
to any actors than can attack. - Add an attack to the
RTSAttackComponent
of these actors, setting its Cooldown, Damage, Range, Acquisition Radius and Chase Radius.
Setting the Damage Type is optional.
If you don't specify a projectile, the damage will be applied immediately. In order to setup a projectile for the unit:
- Create an actor deriving from
RTSProjectile
. - Add a static mesh and any visual effects.
- At the
ProjectileMovement
component, set its Initial Speed (e.g. to 1000). - If you want your projectile to use a ballistic trajectory, check Ballistic Trajectory at the projectile and set the Ballistic Trajectory Factor as you like.
- For dealing area of effect damage, check Apply Area Of Effect and set your area of effect radius and collision filters.
- Set the Fired Sound and Impact Sound to the sound cues to play when the projectile is fired and detonated, respectively.
- At the
RTSAttackComponent
, reference the new projectile in your attack.
- Add the
RTSProductionCostComponent
to everything you want to be produced. - Set the Production Time for these products.
- Set the Resources to any resources required for production.
- Set the Production Cost Type to to Pay Immediately if all costs should be paid in full when starting production, or to Pay Over Time for continuously paying costs (similar to Command & Conquer).
- Set the Refund Factor to the factor to multiply refunded resources with after cancelation.
- Set the Finished Sound to the sound cue to play when the actor spaws after being produced.
- Add the
RTSRequirementsComponent
if the actor should have any requirements, and set the Required Actors.
- Add an
RTSBuilderComponent
to any actors you want to be able to construct buildings. - Set the Constructible Building Classes for these builders.
- Check Enter Construction Site if you want the builder to be unavailable while building (similar to Orcs in WarCraft). In that case, add a
RTSContainableComponent
as well.
- Add an
RTSGathererComponent
to any actor that should be able to gather resources. - Add any resource type the gatherer should be able to gather to Gathered Resources.
- Gathering works similar to attacks, with "damage" and "cooldown". Set Amount Per Gathering to the value to add to the gatherers inventory each time the cooldown is finished.
- Set the Cooldown to the time between two gatherings.
- Set the Capacity to the amount of resources the gatherer can carry before returning to a resource drain.
- Check Needs Return To Drain if the gatherer needs to move to another actor for returning resources (e.g. Age of Empires). Uncheck if they should return all gathered resources immediately when hitting the capacity limit (e.g. Undead in WarCraft).
- Set Range as desired.
- Add all Resource Source Actor Classes the gatherer may gather from (e.g. Undead in Warcraft need Haunted Gold Mine).
- Set the Resource Sweep Radius to the radius in which the gatherer should look for similar resources if their current source is depleted.
- Add an
RTSBountyComponent
to any actors you want to grant bounties to killing players. - Set the Bounty for these actors.
- If you're working on an online game, check Always Relevant for your actor.