Skip to content
CRUSHFORMV1.1.0
GET IT ON FAB

REFERENCECOMPONENTS

UCFBreakableUnitsComponent

MODULECrushformBreakableINCLUDECFBreakableUnitsComponent.hPARENTUSceneComponent

The replicated core of a set of breakable units, each taken through levels 0 (intact) to MaxLevel (broken for good). The owner lays the units out and calls InitUnits on every machine with identical data; a unit's index is its identity everywhere. The authority confirms levels (RaiseUnitLevelOnAuthority) and replicates them with a ring of recent events, a client predicts a level ahead of it (PredictUnitLevel) and the tracker keeps what each machine shows. A subclass says what a unit looks like and where it stands; it never touches the replicated state itself.

Functions

AUTHORITY · server, every machineLOCAL · this machinePURE · read only
UCFBreakableUnitsComponent* FindUnitsForPrimitive(const UPrimitiveComponent* Primitive, int32 ItemIndex, int32& OutUnitIndex)

The units component Primitive stands for a unit of, and that unit's index: through ICFBreakableUnitPart on the primitive, else the first attach parent that knows the primitive. nullptr when none does.

Category
Crushform|Breakable
bool ApplyHitResultOnAuthority(const FHitResult& HitResult, float Strength, FName HitKind)
AUTHORITY

Authority: applies an outside hit on a primitive to the unit it belongs to. The impact point is the hit's location, its direction the trace's (the inverse surface normal for a zero-length trace).

Category
Crushform|Breakable
bool PredictHitResult(const FHitResult& HitResult, float Strength, FName HitKind)

Any machine: the prediction twin of ApplyHitResultOnAuthority.

Category
Crushform|Breakable
bool ApplyHitOnAuthority(int32 UnitIndex, const FCFBreakableHit& Hit)
AUTHORITY

Authority: raises the unit to the level its definition gives this hit (HitResponses), replicates it and plays it. False if nothing changed. Virtual: a subclass whose hits need their own verdict (a glass pane's crack) overrides it.

Category
Crushform|Breakable
bool PredictHit(int32 UnitIndex, const FCFBreakableHit& Hit)

Any machine: shows the hit's level now and waits for the authority; undone after PredictionConfirmTimeoutSeconds. The caller brings its own way to the server.

Category
Crushform|Breakable
int32 GetUnitCount() const
PURE

How many units the owner laid out.

Category
Crushform|Breakable
int32 GetMaxLevel() const
PURE

The highest level a unit can reach, as given to InitUnits; a unit is intact at 0.

Category
Crushform|Breakable
int32 GetUnitLevel(int32 UnitIndex) const
PURE

The level this machine shows: the authority's, or a prediction ahead of it.

Category
Crushform|Breakable
int32 GetConfirmedUnitLevel(int32 UnitIndex) const
PURE

The level the authority confirmed in the current generation.

Category
Crushform|Breakable
bool IsUnitIntact(int32 UnitIndex) const
PURE

True for a valid index whose shown level is 0; false for an invalid index.

Category
Crushform|Breakable
bool PredictUnitLevel(int32 UnitIndex, uint8 Level, const FCFBreakImpact& StoredImpact, uint8 ResponseIndex = CFBreakable::NoResponse)
C++ ONLY

Shows StoredImpact's level now, ahead of the authority, with the units GatherUnitsRaisedWith adds. False for an invalid index or level, or when the unit already shows that level or more.

bool RaiseUnitLevelOnAuthority(int32 UnitIndex, uint8 Level, const FCFBreakImpact& StoredImpact, uint8 ResponseIndex = CFBreakable::NoResponse)
AUTHORITYC++ ONLY

Authority: confirms Level for the unit and the units GatherUnitsRaisedWith adds, replicates it, plays it here and tells OnUnitsRaisedOnAuthority. False for a non-authority, an invalid index or level, or a unit already at that level or more.

bool CancelPrediction(int32 UnitIndex)
C++ ONLY

Rolls the unit's prediction back to the confirmed level, and with it the predictions of the units GatherUnitsRaisedWith adds. False for an invalid index or a unit with no prediction.

void ApplyGeneration(uint8 InGeneration)
C++ ONLY

Any machine: the first generation this component learns (from here or from its replicated levels) is taken whatever it is; after that a newer one puts every unit back to intact here at once, and an equal or older one is ignored. The authority also empties the replicated levels and the event ring.

int32 FindUnitForPrimitive(const UPrimitiveComponent* Primitive, int32 ItemIndex) const
PUREC++ ONLY

The unit the primitive (and the instance of it, ItemIndex) stands for, or INDEX_NONE. Called for primitives attached below this component.

Events

FCFOnUnitLevelChangedDelegate OnUnitLevelChangedNative
C++ ONLY
(UCFBreakableUnitsComponent&, int32, uint8, uint8)

Both fire on every machine whenever a unit's shown level changes. A late joiner's catch-up (init at 0, then the replicated levels) fires them for every unit already raised, so no one-shot effect belongs here. Handlers may raise, predict or cancel other units and apply a generation.

FCFOnUnitLevelChangedDynamicDelegate OnUnitLevelChanged
(UCFBreakableUnitsComponent* Units, int32 UnitIndex, int32 Level, int32 PreviousLevel)
Category
Crushform|Breakable