> For the complete documentation index, see [llms.txt](https://docs.febucci.com/text-animator-unreal/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.febucci.com/text-animator-unreal/typewriter/trigger-events-when-typing.md).

# Trigger Events when typing

Events are special tags that let you send messages (delegates with a `FEventMarker` parameter) to any listener, once the typewriter has reached a specific part of the text.

<figure><img src="/files/tiFfa2C8N3FO4uciCVTS" alt="textanimatorgif2febucci"><figcaption><p>Scene 'Example 3 - Events'</p></figcaption></figure>

{% hint style="danger" %}
Events will work only if the typewriter is enabled.&#x20;
{% endhint %}

***

## Overview <a href="#overview" id="overview"></a>

You can write events in your text by using rich text tags.

### Formatting <a href="#formatting" id="formatting"></a>

Event’s messages are preceded by a question mark, like this: `<?eventMessage>`.

**Example:** To call an event named ‘shakeCamera’, write: `<?shakeCamera>`

{% hint style="info" %}
An event can have any kind of tag, including built-in effect’s ones.
{% endhint %}

{% hint style="warning" %}
Events are case sensitive. Writing `<?camshake>` is not the same as writing `<?camShake>`. Be careful! (or use the `FString.ToLower()` method in your scripts to account for that.)
{% endhint %}

### Parameters <a href="#parameters" id="parameters"></a>

Events can have one or multiple parameters (starting with the `=` sign for the first, and then separating the others with a comma `,`), to allow you to send multiple data to your code or Blueprints.

* One parameter: `<?eventID=parameter1>`, will result in a message “**eventID**” and one parameter “**parameter1**”.
* Multiple parameters: `<?eventID=p1,p2>`, will result in a message “**eventID**” and parameters “**p1**” and “**p2**”.

***

## Listening to events from C++ <a href="#listening-to-events" id="listening-to-events"></a>

The code that you want to listen for events/messages must subscribe to the `FOnMessage` delegate inside the `UTypewriterCore` class.

Example:

{% code expandable="true" %}

```cpp
//Inside your C++ class (for example, inside a custom UActorComponent)

#pragma once

#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "TextAnimatorFebucci/Public/Typewriter/TypewriterCore.h"
#include "TextAnimatorFebucci/Public/Widgets/AnimTextBlock.h"
#include "YourClassName.generated.h"

UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class YOURPROJECT_API UYourClassName : public UActorComponent
{
    GENERATED_BODY()

public:
    UAnimTextBlock* AnimatedText;

//Adds and removes listening to callback
protected:
    virtual void BeginPlay() override 
    {
        Super::BeginPlay();
        
        if (AnimatedText)
        {
            AnimatedText->Typewriter->OnMessage.AddDynamic(this, &UYourClassName::OnTypewriterMessage);
        }
     }
    virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
    {
        if (AnimatedText)
        {
            AnimatedText->Typewriter->OnMessage.RemoveDynamic(this, &UYourClassName::OnTypewriterMessage);
        }
    
        Super::EndPlay(EndPlayReason);
    }

    //Does stuff based on delegate
    UFUNCTION()
    void OnTypewriterMessage(const FEventMarker& EventMarker)
    {
        if (EventMarker.Name.Equals(TEXT("something"), ESearchCase::IgnoreCase))
        {
            // Do something
        }
    }
}
```

{% endcode %}

{% hint style="warning" %}
Note how the message string `TEXT("something")` has no `<`, `?` and `>` characters.
{% endhint %}

## Listening to events from Blueprints <a href="#listening-to-events" id="listening-to-events"></a>

Subscribing to events from Blueprints is also straightforward. Assuming you have a reference to an AnimTextBlock in one of your custom widgets, just bind an event to the `OnMessage` delegate of its typewriter on On Initialized and unbind it on Destruct.

Example:

<figure><img src="/files/XZI6hYrDU8XxUmrJNFij" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
You can find a more complex in the Plugin content in the "**Examples/2\_Events/WBP\_2\_Events** Graph.&#x20;
{% endhint %}
