> 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/soap-core-assets/scriptable-event/faq.md).

# FAQ

Scriptable Event

## When should I use a Scriptable Event or a Scriptable Variable?&#x20;

It’s not a black or white answer. The more you use SOAP, the clearer it becomes when to choose one approach over the other. Until then, I can provide a few examples for each use case. These examples are helpful, but they are not the only way. Everyone has their own preferences, and sometimes you might feel like using a different solution for a specific task.

Scriptable Variables are mostly useful for solving dependencies of a single element (or global variable) across different parts of the game:

\- Player (and anything related to it, like its stats)

\- Settings (volume, quality, options, etc.)

\- Score, Coins, Level Index

\- Boss (and anything related to it, like its stats)

\- Game States (TutorialComplete, QuestXCompleted)

Scriptable Events are mostly useful for communicating indirectly with other components:

\- OnPlayerDamaged(int damageAmount), OnPlayerDeath

\- OnLevelCompleted(int levelIndex)

\- OnCoinsCollected(int amount of Coins)

\- OnPowerUpCollected(Vector3 position) - to spawn a VFX at that location

Personally, I use Scriptable Events for UI and for visual feedback (camera shake, VFX, sound, etc.). Many developers use them for game logic as well, but I prefer to keep that in code and use static events or an event bus because I find it easier to track down game flow through code.

Another example: If you want to show the score in the UI (using TextMeshPro). Should you use a Scriptable variable or a scriptable event? You can use both but I would choose to bind to a scriptable variable. For this, use the BindTextMeshPro Component. Attach that to the TextMeshPro GameObject and the text will refresh every time the value of the variable changes.
