# Best Practices

***

### 1. Use Descriptive Names

Add descriptions to complex actions for better organization:

```
Action 1: "Fade in UI"
Action 2: "Play intro sound"
Action 3: "Enable player input"
```

### 2. Organize with Categories

Use `ActionCategory` to keep custom actions organized:

```csharp
[ActionCategory("MyGame/Combat")]
[ActionCategory("MyGame/UI")]
[ActionCategory("MyGame/Audio")]
```

### 3. Use Foldouts for Complex Actions

Group related properties with `Foldout` attributes for cleaner inspectors.

### 4. Leverage Conditional Attributes

Use `ShowIf`/`HideIf` to hide irrelevant properties based on settings.

### 5. Cache References in Initialize

Override `Initialize()` to cache frequently accessed components:

```csharp
[NonSerialized] private Transform _cachedTransform;

public override void Initialize(FlowPlayer player)
{
    base.Initialize(player);
    _cachedTransform = player.transform;
}
```

### 6. Always Yield in Execute

Every `DoAction()` method must yield at least once:

```csharp
protected override IEnumerator DoAction()
{
    DoThing();
    yield return null; // required
}
```

### 7. Use Events for Integration

Connect FlowPlayer events to other systems:

```csharp
flowPlayer.OnComplete.AddListener(EnablePlayerControl);
flowPlayer.OnActionExecuted.AddListener(UpdateProgressUI);
```

### 8. Use Triggers Instead of Code

For common scenarios (input, collisions, timers), use the built-in trigger components instead of writing custom scripts. This keeps your project maintainable and accessible to non-programmers.

### 9. Combine Juice Actions for Impact

Layer multiple Juice actions for satisfying feedback:

```
Action 1: PunchScale    (quick pop)
Action 2: PunchPosition (slight bounce)
Action 3: ScreenShake   (subtle camera shake)
Action 4: PlayAudio     (impact sound)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://beelabs-dev.gitbook.io/beelabs-docs/flow-of-action/best-practices.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
