Unit Formation
Guide on how to integrate formation behaviour with Unit System demo scripts
Last updated
Guide on how to integrate formation behaviour with Unit System demo scripts
Last updated
This page is for guiding you through the process of basic integration for package. Refer to the if you need more information.
If you do not have Unit Formation package present, then follow it's guide for import and scene setup:
Add FormationPlacement prefab in scene, configure it and its input
You can skip FormationUnit
component, but each unit still must have a script which implements IFormationUnit
. You can do this by:
Updating your unit prefabs from using NavMeshMovement
to FormationNavMeshMovement
instead. It only extends functionality for the formation by implementing IFormationUnit
interface. This way any update that happens to the formation position will cancel current active task that the units may have.
Or if you are not using the provided movement scripts, make sure your movement script also implements IFormationUnit
to receive a command to move unit to the new position in formation.
In this step we need to sync selected units with formation package, so that formation placement may be used with all the selected units.
Add SelectedUnitsFormation
component to your player, this will delegate any selection changes on EntitySelectionManager
to the FormationPlacement
component. This component also requires the Player reference, to make sure there are no unowned entities in the formation unit list.
Now you should already be able to use Formation Placement actions with the selected units.
This step adds formation capability to normal interactions for the selected units. When you are using provided demo scripts for interactions (TargetedUnitInteractions
component) it already positions units in formation when there is no entity to interact with in that position. We now want to use the Unit Formation package to achieve this.
If you are not using provided interaction components, you can skip this step.
Add FormationPlacement prefab from the Unit Formation package to your scene and configure it for your project.
If you followed the Set up Player, find the for the Player Interactions object of your Player in the scene, and replace the TargetedUnitInteractions
component on it with TargetedFormationUnitInteractions
.
This can be done by removing current component and replacing it with a new one, and then make sure all the references in scene are now pointing to the new component.
Another way to do it is to enable Debug view in Inspector and replace the script reference to the new class. And that's it.