Table of Contents

Social Features

Voice Chat

if (Player.IsLocal)
{
    Game.SetVoiceEnabled(false);
}

Text Chat

You can send and receive chat messages from your game using the Chat API.

A common use case is enabling admin commands to make testing your game easier

For example in a GameManager component:

public override void Awake()
{
    Chat.RegisterChatCommandHandler(RunChatCommand);
}

public void RunChatCommand(Player p, string command)
{
    var parts = command.Split(' ');
    var cmd = parts[0].ToLowerInvariant();
    MyPlayer player = (MyPlayer)p;
    var allowCommands = Game.LaunchedFromEditor;
    if (player.UserId == "your_user_id") allowCommands = true;

    if (!allowCommands)
    {
        return;
    }

    switch (cmd)
    {
        case "help": 
        {
            Chat.SendMessage(p,"\nChat Commands:\n"+
            "/z[oom] <multiplier> : Set camera zoom\n"+
            "/s[tart] : start round immediately\n"+
            "/sp[eed] <multiplier>\n"+
            break;
        }
        case "s":
        case "start":
        {
            State = GameState.CountingDown;
            Countdown.Set(0);
            break;
        }
        case "z":
        case "zoom":
        {
            if (parts.Length != 2)
            {
                Chat.SendMessage(player, "/zoom needs a zoom value as a parameter.");
                break;
            }
            if (float.TryParse(parts[1], out var z))
            {
                player.CurrentZoomLevel.Set(z);
            }
            break;
        }
        case "sp":
        case "speed":
        {
            if (parts.Length != 2)
            {
                Chat.SendMessage(player, "/speed needs a speed value as a parameter.");
                break;
            }
            if (float.TryParse(parts[1], out var s))
            {
                player.CheatSpeedMultiplier.Set(s);
            }
            break;
        }
    }
}

Note: not all players will have text/voice chat enabled. Both parental controls and moderation mutes disable the text box, so you cannot soley rely on chat for critical gameplay systems. For similar use cases consider using the (api/notifications) Notifications system.