UCrimsonEquipmentInstance
Runtime object representing a single equipped piece of gear. One instance is created per equipped item and destroyed when it is unequipped. Manages spawned actors and fires lifecycle hooks. Subclass to add per-item gameplay logic.
Lifecycle Hooks
| Hook | Called When | Override To |
|---|---|---|
| OnEquipped() | After ability sets are granted and visual actors are spawned - authority only. | Apply item-specific gameplay effects (stat GEs, skill tree activation, hotbar slot registration, activate GAS tags). |
| OnUnequipped() | Before actors are destroyed and ability sets are revoked - authority only. | Remove everything applied in OnEquipped. Mirror every operation in reverse. |
OnEquipped / OnUnequipped are Server-Only
Both hooks execute on the authority only. For client-side visual reactions (HUD updates, particle effects), listen to the replicated
SpawnedActors rep notify or subscribe to the FCrimsonEquipmentChangedMessage broadcast.Source Object Bridge Pattern
The SourceObject is the object that triggered the equip - typically an inventory item instance. CrimsonEquipment treats it as an opaque UObject*. Retrieve it from the instance and cast to your type.
// When equipping - pass anythingEqMgr->EquipItem(UBP_Sword::StaticClass(), MyInventoryItem);// In OnEquipped - cast back to your typevoid UMySwordInstance::OnEquipped_Implementation(){if (UCrimsonInventoryItemInstance* Item =Cast<UCrimsonInventoryItemInstance>(GetSourceObject())){// read item stats, activate skill tree, etc.}}
Accessors
| Function | Returns | Description |
|---|---|---|
| GetSourceObject() | UObject* | The object passed to EquipItem. Cast to your item type. |
| GetPawn() | APawn* | The owning pawn. |
| GetTypedPawn(PawnType) | APawn* | Typed getter - avoids casting in Blueprint. DeterminesOutputType. |
| GetSpawnedActors() | TArray<AActor*> | All visual/functional actors currently spawned by this equipment. |
Replication
UCrimsonEquipmentInstance is a replicated UObject. The outer is always set to the owning APawn (required by UE for UObject replication - see UE-127172). Subobjects are registered in UCrimsonEquipmentManagerComponent::ReadyForReplication. SourceObject and SpawnedActors are replicated properties.
Subclassing Example
UCLASS()class UMySwordInstance : public UCrimsonEquipmentInstance{GENERATED_BODY()// Optional: custom replicated stateUPROPERTY(Replicated)float CurrentDurability = 100.f;public:void OnEquipped_Implementation() override;void OnUnequipped_Implementation() override;};void UMySwordInstance::OnEquipped_Implementation(){Super::OnEquipped_Implementation();// Apply sword-specific GE, register hotbar slot, etc.}void UMySwordInstance::OnUnequipped_Implementation(){// Undo everything from OnEquipped in reverse orderSuper::OnUnequipped_Implementation();}