> For the complete documentation index, see [llms.txt](https://dante-3.gitbook.io/dante-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dante-3.gitbook.io/dante-docs/modular-attachment-system/modular-attachment-subsystem/methods.md).

# Methods

## Tag Registry

### `RegisterComponent`

```cpp
void RegisterComponent(FGameplayTag Tag, UModularAttachmentComponent* Component);
```

Adds a component to the `TagToComponents` map under the given tag. Called automatically by the component during `ApplyFragmentTree` (for each fragment's tag) and `OnAttachmentLoadFinished` (for the component's slot tag).

### `UnregisterComponent`

```cpp
void UnregisterComponent(FGameplayTag Tag, UModularAttachmentComponent* Component);
```

Removes a component from the map. Called during `UnloadAttachment`.

### `GetComponentsByTag`

```cpp
UFUNCTION(BlueprintCallable, Category = "Modular Attachment System")
TArray<UModularAttachmentComponent*> GetComponentsByTag(FGameplayTag Tag);
```

Returns all live components registered under the given tag. Lazily cleans stale weak pointers during iteration.

**Example — find all optic slots in the world:**

```cpp
TArray<UModularAttachmentComponent*> Optics =
    Sub->GetComponentsByTag(FGameplayTag::RequestGameplayTag("ModularAttachment.Slot.Optic"));
```

## &#x20;Bulk Operations

### `UnloadAll`

```cpp
UFUNCTION(BlueprintCallable, Category = "Modular Attachment System")
void UnloadAll();
```

Immediately releases all cached assets — every streaming handle is cancelled, every cache entry removed. Empties the tag registry and pending timers. Use before level transitions or when all attachments need to disappear.

> **Warning:** This calls `ExecuteDeferredUnload` on every entry synchronously. Components' `OnAttachmentUnloaded` will fire, resetting their state.

### `UnloadByTag`

```cpp
UFUNCTION(BlueprintCallable, Category = "Modular Attachment System")
void UnloadByTag(FGameplayTag Tag);
```

Calls `UnloadAttachment()` on every component registered under the given tag, then removes the tag entry from the registry.

**Example — unload all muzzle attachments:**

```cpp
Sub->UnloadByTag(FGameplayTag::RequestGameplayTag("ModularAttachment.Slot.Muzzle"));
```

### `ReloadAll`

```cpp
UFUNCTION(BlueprintCallable, Category = "Modular Attachment System")
void ReloadAll();
```

1. Collects all currently registered components
2. Calls `UnloadAll()` to tear down everything
3. Calls `OnAttachmentUnloaded()` + `LoadAttachment()` on each component

Useful for hot-reload scenarios or when definition assets change at runtime.

## Event Broadcasting

### `BroadcastToTag`

```cpp
UFUNCTION(BlueprintCallable, Category = "Modular Attachment System")
void BroadcastToTag(FGameplayTag TargetTag, const FAttachmentEventPayload& Payload);
```

Routes an event payload to all components registered under `TargetTag`. Fires in this order:

```
BroadcastToTag(TargetTag, Payload)
  │
  ├─► OnTagEventNative.Broadcast(TargetTag, Payload)    C++ global listeners
  │
  └─► For each Component registered under TargetTag:
        Component→OnAttachmentEvent.Broadcast(Payload)   Blueprint-bindable
```

**Blueprint usage:**

1. Get the subsystem via **Get World Subsystem**
2. Call **Broadcast To Tag**
3. Fill in `TargetTag` (e.g., `ModularAttachment.Slot.Optic`)
4. Fill in the `FAttachmentEventPayload` struct

**C++ usage:**

```cpp
FAttachmentEventPayload Payload;
Payload.EventTag = FGameplayTag::RequestGameplayTag("ModularAttachment.Event.Aim");
Payload.TargetTag = FGameplayTag::RequestGameplayTag("ModularAttachment.Slot.Optic");
Payload.Instigator = GetOwner();
Payload.Values.Add(
    FGameplayTag::RequestGameplayTag("ModularAttachment.Value.Zoom"), 4.0f);

Sub->BroadcastToTag(Payload.TargetTag, Payload);
```

### `OnTagEventNative`

```cpp
FOnAttachmentTagEvent OnTagEventNative;
```

C++-only multicast delegate (`DECLARE_MULTICAST_DELEGATE_TwoParams`). Fires for every `BroadcastToTag` call — bind to this if you need a system-wide listener that isn't tied to a specific component.

```cpp
Sub->OnTagEventNative.AddLambda([](FGameplayTag Tag, const FAttachmentEventPayload& Payload)
{
    UE_LOG(LogTemp, Log, TEXT("Event %s → %s"), *Payload.EventTag.ToString(), *Tag.ToString());
});
```
