> For the complete documentation index, see [llms.txt](https://obvious-game.gitbook.io/soap/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://obvious-game.gitbook.io/soap/scene-documentation/4_scriptableevents/firing-events-from-code.md).

# Firing Events from code

Events are useful to trigger things like VFX, menus, or even gameplay elements. Let’s look at the events that are fired from Health.cs on the prefab\_player. &#x20;

* OnPlayerDamaged -> ScriptableEventInt&#x20;
* OnPlayerHealed -> ScriptableEventInt&#x20;
* OnPlayerDeath -> ScriptableEventNoParam&#x20;

<figure><img src="https://lh7-rt.googleusercontent.com/docsz/AD_4nXd8DGL3Bq9z-KX__LraZOOpeP-ZkBoKyLrIXIcFtHVtqtZYMIiBNfAZqsaQnnp6vSYD-HJ2BO8hozPlucENNhmfgh-zRWJdcitRle0pFIFIfwhVWOI9ZwH9szhsmVzHkvo_pwKvUYvwQcBPOSoC0N1d52Tr?key=npvPcHMgF_O4Om_5f5S8Bw" alt="" width="375"><figcaption></figcaption></figure>

It is simple to fire these events from code, you simply call the Raise() method. Here is an example in Health.cs:&#x20;

```csharp
private void OnDamaged(float value)
{
    if (_currentHealth <= 0f && !_isDead)
        OnDeath();
    else
        _onPlayerDamaged.Raise(Mathf.RoundToInt(value));
}

private void OnHealed(float value)
{
    _onPlayerHealed.Raise(Mathf.RoundToInt(value));
}

private void OnDeath()
{
    _onPlayerDeath.Raise();
    _isDead = true;
}
```


---

# 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://obvious-game.gitbook.io/soap/scene-documentation/4_scriptableevents/firing-events-from-code.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.
