Unit Selection
  • Welcome
    • πŸ‘‹Hello
    • πŸ—ΊοΈRoadmap
    • ⛑️Support & Community
    • πŸŽ“Changelog
  • Getting started
    • πŸ”ŒImport package
    • πŸ› οΈAdd selection to scene
    • 🦲Add selection to units
    • β›³Add visuals to units
  • How it works
    • 🎯Active Selections
    • 🫡Unit Selector
    • πŸ”’Quick Access Selector
    • ⬛Selection Area
      • πŸ”²2D Rectangle
      • 🧊3D Cube
    • πŸ’ Selectable Unit
      • πŸ“Selection Bounds
      • β­•Selection Indicator
    • Selectable Group Unit
    • ⌨️Input Controls
    • πŸ‘·β€β™€οΈUnit Management
Powered by GitBook
On this page
  • Introduction
  • Overview
  • IUnitManager Interface
  • How it works
  • UnitManager
  • UnitManagementEvents
  • ManageUnitObject Component
  • Customisation
  • Unit Destruct or Deactivation
  1. How it works

Unit Management

Learn how works! Managing selectable unit references for the selection system.

PreviousInput Controls

Last updated 18 days ago

Introduction

This topic is generally the last one you'll need to consider, and many games might not require any changes at all. However, we provide public interfaces allowing full customisation of this behaviour should you need to manage it yourself. Provided component ManageUnitObject implements this behaviour for you, if a custom one is used remove this component from your game objects.

Overview

The unit manager is crucial for supplying valid selectable units to the selection system. This communication is facilitated by the IUnitManager interface. It's primary function is to provide a list of valid units for selection.

IUnitManager Interface

public interface IUnitManager
{
    public List<ISelectable> SelectableUnits { get; }
}

By implementing this interface you should provide custom list of valid units at any point, like switching between different lists based on some player action. Though for filtering itself there is a more straightforward approach using filter . Note that if the unit management interface has no selectable units, drag selection will not work, only units present in the list may be selected.

How it works

Using the ManageUnitObject component on selectable units means that the UnitManager handles everything, requiring no further action on your part.

UnitManager

This singleton manages all active and valid selectable units that have the ManageUnitObject component. It provides interfaces to add, remove, and clear units, although typically, you won't need to use these directly.

UnitManagementEvents

Provides events for managing unit lifecycle events within the game. This class is essential for cleaning up no longer valid unit references in the selection systems. It currently holds only one event named OnUnitRemoved and it should be invoked when unit is no longer valid for selection (was removed from SelectableUnits list). This makes sure that any reference using this object is removed and prevents potential null reference exceptions.

If ManageUnitObject Component is used, this is handled internally. Read it's documentation for further information.

ManageUnitObject Component

This component is part of drag selection feature and can be added through SelectableUnit component or manually. It notifies the UnitManager singleton about any changes in the unit's state like when they are instantiated, enabled, disabled, unloaded or otherwise destroyed.

Customisation

If you desire to create your own behaviour instead of using this singleton, you replace it by implementing your own IUnitManager. All code is accessible and well documented, adjusting it or create your own.

Unit Destruct or Deactivation

When selectable units are no longer valid for selection, destroyed or otherwise disabled, selection system must be notified to prevent using no longer valid game objects. It would look something like this:

// Do this on unit when deactivating or destroying your unit
ISelectable selectableUnit = GetComponent<ISelectable>();
UnitManagementEvents.OnUnitRemoved.Invoke(selectableUnit);

This is to prevent null references inside the system; for performance gain it never checks for a null reference.

In case you into problems creating your own manager, we are always here for you .

πŸ‘·β€β™€οΈ
General Support
IFilterSelection interface