Webhooks Free now available for Photon Fusion and Quantum – 4 examples of webhooks
Webhooks are a crucial tool for developers building multiplayer games because they let your game communicate directly with external systems from the Photon Cloud. Photon Engine now provides free webhooks for Photon Fusion and Photon Quantum, allowing you to automate key actions essential for multiplayer games running in the Public and Premium Clouds.
With webhooks, events like CreateGame, JoinGame, or CloseGame automatically trigger HTTP requests that can interact with custom backends or liveops services providers. The Replay streaming feature is also available for Quantum games. This simplifies processes like authenticated requests and logging, improving overall game engagement results.
Why Use Webhooks?
- CreateGame Security: One of the main advantages is that the CreateGame webhook adds an additional security layer. When a game session is created, this webhook gives you the ability to validate the request against external systems, ensuring the game is configured correctly before it starts.
- Replay Functionality for Quantum: For developers using Photon Quantum, the ReplayStart and ReplayChunk webhooks enable the remote capture of game replays. These webhooks provide the necessary hooks to save and stream past game states in your custom backend to store and manage the replay data of all players. Local replay is already available in the engine.
By default, Photon provides a set of standard webhooks available to all developers for Free, ensuring that common game events like room creation, player join/leave, and game session close are covered. For those with more advanced needs, custom webhooks are available for Enterprise customers, allowing for tailored integrations that can handle complex workflows unique to your game.
Examples of How to Use Webhooks
Webhooks in Photon Fusion and Photon Quantum are designed to give you more flexibility and control over how your game interacts with external systems. Here are some practical examples of how you can use them in your game development workflow:
1. Replay Integration with ReplayStart and ReplayChunk (Quantum)
In Photon Quantum, one standout feature is the ability to record and store gameplay replays. Using the ReplayStart and ReplayChunk webhooks, you can capture and manage replay data during and after matches. This is especially useful for esports or any game where replay functionality is important for post-game analysis.
Example:
- During a multiplayer fighting game, the ReplayStart webhook triggers when a match begins, signaling your backend to prepare storage for replay data.
- As the match progresses, the ReplayChunk webhook sends small chunks of the game state to your backend at a custom interval, storing the match replay in real-time.
- After the match ends, the replay is saved and can be accessed by players or reviewers for analysis.
2. Validating Game Settings with the CreateGame Webhook
One of the most common use cases is ensuring that every new game session is configured correctly. When a player creates a new game (e.g., starting a match or creating a room), the CreateGame webhook sends an HTTP request to your backend. This is a great opportunity to validate game settings against your server logic—whether it’s checking that the map is available, verifying that the player has permission to create games, or ensuring that certain game rules are in place.
Example:
- A player creates a new game session in a competitive multiplayer shooter.
- The CreateGame webhook fires, sending the game configuration (e.g., map, game mode, max players) to your backend.
- Your backend checks that the map is supported for the selected game mode and that the player is authorized to start a competitive match.
- If valid, the game is created; if not, the player receives an error message.
3. Logging Player Activity with JoinGame and LeaveGame Webhooks
Tracking when players join and leave game sessions can be essential for telemetry, metrics, and live operations. Using the JoinGame and LeaveGame webhooks, you can log these activities into a custom backend for analytics or use them to trigger specific actions, such as starting live leaderboards or adjusting matchmaking parameters.
Example:
- A player joins a session in a multiplayer racing game.
- The JoinGame webhook triggers, sending the player’s ID and session details to a logging service.
- Later, when the player leaves the session, the LeaveGame webhook fires, logging the time spent in the session.
- These logs are used to update player statistics, such as win/loss ratio, or to adjust dynamic difficulty scaling for future matches.
4. Handling Match Results with the GameResult Webhook
Photon Quantum includes the GameResult client verification webhook, which is particularly useful for games that need to record match outcomes, such as an RTS or sports game. When a match ends, this client webhook sends the game’s result to your backend, allowing you to validate and update player rankings, record match history, or distribute in-game rewards.
Example:
- After a battle in an RTS game, the GameResult webhook is triggered.
- The webhook sends the match results, including the winner, the final score, and any key stats, to your backend.
- Your backend then processes this information to update player rankings and issue rewards, like experience points or in-game currency.
5. Error Handling with WebhookError
For developers integrating webhooks, it’s important to handle errors effectively. Photon’s WebhookError event helps you monitor when a webhook fails, allowing you to quickly diagnose and resolve issues in your integration.
Example:
- A player creates a new game, but the CreateGame webhook fails due to a misconfigured endpoint or error on your backend.
- The WebhookError response notifies you of the failure along with an error message and request details.
- You can then troubleshoot the issue (e.g., by fixing the endpoint or adding error-handling logic) to prevent future failures.