> 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-component/methods.md).

# Methods

{% tabs %}
{% tab title="Blueprint" %}
Open the actor's Component panel → **+ Add** → **ModularAttachmentComponent**.\
Assign a definition to the **Attachment Definition Asset** slot in the Details panel.
{% endtab %}

{% tab title="C++ (constructor)" %}

```cpp
// MyWeapon.h
UPROPERTY(VisibleAnywhere, Category = "Attachments")
TObjectPtr<UModularAttachmentComponent> OpticSlot;
```

```cpp
// MyWeapon.cpp
OpticSlot = CreateDefaultSubobject<UModularAttachmentComponent>(TEXT("OpticSlot"));
OpticSlot->SetupAttachment(RootComponent);
OpticSlot->ComponentTag = FGameplayTag::RequestGameplayTag("ModularAttachment.Slot.Optic");
```

{% endtab %}
{% endtabs %}

***

## Methods — Load / Unload

### `LoadAttachment`

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

Begins the three-phase async load pipeline via the subsystem. No-op if already loading or loaded. Deduped — if another component already requested the same definition, shares the existing streaming handle.

### `UnloadAttachment`

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

Removes all spawned fragment components, unregisters from the subsystem, and decrements the cache ref count. When the ref count reaches zero, the subsystem schedules a deferred unload on the next tick.

### `SwapAttachment`

```cpp
UFUNCTION(BlueprintCallable, Category = "Modular Attachment System")
void SwapAttachment(TSoftObjectPtr<UModularAttachmentDefinition> NewDefinition);
```

Atomic unload → load. Equivalent to:

```cpp
UnloadAttachment();
AttachmentDefinitionAsset = NewDefinition;
LoadAttachment();
```

***

## Methods — State Queries

### `IsAttachmentLoaded`

```cpp
UFUNCTION(BlueprintPure, Category = "Modular Attachment System")
bool IsAttachmentLoaded() const;
```

Returns `true` when `LoadState == Loaded` — all fragments applied, spawned components valid.

### `GetLoadState`

```cpp
UFUNCTION(BlueprintPure, Category = "Modular Attachment System")
EAttachmentLoadState GetLoadState() const;
```

| Value       | Meaning                                       |
| ----------- | --------------------------------------------- |
| `NotLoaded` | No definition assigned or unloaded            |
| `Loading`   | Async streaming in progress                   |
| `Loaded`    | All fragments applied successfully            |
| `Failed`    | Load failed (null definition, missing assets) |

***

## Methods — Fragment Access

### `GetFragmentByTag`

```cpp
UFUNCTION(BlueprintPure, Category = "Modular Attachment System")
UModularAttachmentFragment* GetFragmentByTag(FGameplayTag Tag) const;
```

Returns the fragment object registered under the given tag, or `nullptr`. Use this to read fragment properties (mesh path, socket name, etc.) or cast to a specific subclass.

### `GetSpawnedComponentsByFragmentTag`

```cpp
UFUNCTION(BlueprintPure, Category = "Modular Attachment System")
TArray<UActorComponent*> GetSpawnedComponentsByFragmentTag(FGameplayTag Tag) const;
```

Returns all actor components spawned by the fragment with the matching tag. Useful when a fragment creates multiple components.

### `GetSpawnedComponentByFragmentTag`

```cpp
UFUNCTION(BlueprintCallable, Category = "Modular Attachment System",
          meta = (DeterminesOutputType = "ComponentClass"))
UActorComponent* GetSpawnedComponentByFragmentTag(FGameplayTag Tag,
                                                   TSubclassOf<UActorComponent> ComponentClass) const;
```

Returns the first spawned component matching the given class. In Blueprint, the output pin type automatically follows `ComponentClass` via `DeterminesOutputType` — select `SkeletalMeshComponent` and the pin becomes `USkeletalMeshComponent*`.

### Typed Convenience Getters

These return specific component types without requiring a class pin:

| Method                                       | Returns                   | Use Case                                                            |
| -------------------------------------------- | ------------------------- | ------------------------------------------------------------------- |
| `GetMeshComponentByFragmentTag(Tag)`         | `UMeshComponent*`         | `SetMaterial`, `SetVisibility` — works for both static and skeletal |
| `GetStaticMeshComponentByFragmentTag(Tag)`   | `UStaticMeshComponent*`   | `SetStaticMesh`, material overrides                                 |
| `GetSkeletalMeshComponentByFragmentTag(Tag)` | `USkeletalMeshComponent*` | `PlayAnimation`, `SetAnimInstanceClass`, leader pose                |

**C++ template:**

```cpp
template <typename T>
T* GetTypedSpawnedComponent(FGameplayTag Tag) const;
```

Returns the first spawned component castable to `T`. Usage:

```cpp
USkeletalMeshComponent* Skel = Comp->GetTypedSpawnedComponent<USkeletalMeshComponent>(Tag);
```

***
