Xenko

OPEN / CLOSE
  • Features
  • Blog
  • Documentation
  • Community
(icon) Download

  • Facebook
  • Twitter
  • YouTube

LANGUAGE

OPEN / CLOSE
  • English
  • Manual
  • API
  • Release notes
    Show / Hide Table of Contents

    Events

    Intermediate Programmer

    Events facilitate communication between scripts. They work one-way, broadcast from broadcasters to receivers.

    For example, imagine your game has a "Game Over" state that occurs when the player dies. To handle this, you can create a "Game Over" event, which is broadcast to all scripts with receivers listening for the event. When the event is broadcast, the receivers run appropriate scripts to handle the Game Over event (eg reset enemies, replace level objects, start a new timer, etc).

    Note

    Events are handled entirely in scripts. You can't configure them in Game Studio.

    Create and broadcast an event

    Broadcasters in the Xenko API are of type EventKey. They use the method Broadcast to broadcast events to receivers.

    For example, this code creates a "Game Over" event:

    public static class GlobalEvents
    {
        public static EventKey GameOverEventKey = new EventKey("Global", "Game Over");
    
        public static void SendGameOverEvent()
        {
            GameOverEventKey.Broadcast();
        }
    }
    

    Create a receiver

    Receivers in the Xenko API are of type EventReceiver.

    To receive the "Game Over" event described above, use:

    var gameOverListener = new EventReceiver(GlobalEvents.GameOverEventKey);
    var gameIsOver = gameOverListener.TryReceive();
    
    //Or in Async
    await gameOverListener.ReceiveAsync();
    

    See also

    • Types of script
    • Create a script
    • Use a script
    • Public properties and fields
    • Scheduling and priorities
    • Debugging
    • Preprocessor variables
    • Improve this Doc

    Back to top

    Copyright © 2016 Silicon Studio
    Generated by DocFX