Talo logoDocsBlogShowcase
Back to blog

How to see live online player counts in your Godot game

4 min read
How to see live online player counts in your Godot game

TL;DR

Talo makes it easy to track player counts in your Godot game. In this tutorial, you'll build a simple project that shows how to track online player counts using Talo's player groups.

How many players are online?

Knowing how many players are currently playing your game is something that almost everyone wants to know. It's always great to see player counts climbing, especially after new updates or announcements.

But how can you track this? You could build your own tracking system, but that's time-consuming and complex - you've got a game to build! That's why we built Talo, a game backend platform that makes it easy to understand player behaviour and gain oversight over your game's data. In this tutorial, we'll show you how to use Talo to track player counts in your Godot game.

Online player counts with Talo

Talo makes it easy to segment your players using player groups. You can use player groups to create distinct buckets of players. For example, in this tutorial, you'll use player groups to check for players with a custom "online" property.

When your Godot game starts, you'll identify the player and set the "online" property to true. When they exit the game, you'll set it to false. Using Talo's new pinned groups feature in the dashoard, you can see the number of players in the "online" group in real-time.

Setup the Talo Godot plugin

You need to start by setting up the Talo Godot plugin. You can do this by downloading the plugin from the Godot Asset Library (or by searching "Talo Game Services" in the AssetLib tab of the Godot editor). You can also find the latest version of the plugin on itch.io.

Install Talo from the AssetLib tab

Once you've downloaded the plugin, import it (typically you want to install plugins under the addons folder) and enable it in the Project > Project Settings > Plugins window.

Enable the Talo plugin in the project settings

You can now run your game - this will create a settings.cfg asset inside the folder where you installed the plugin - you'll need this later. To learn more about how to configure Talo, including how to configure your self-hosted version, check out the docs.

Generating an access key

Next you need to generate an access key for your game. Visit the Talo dashboard, login or create an account (and confirm your email address). Once logged in, create a new game (if you need to) and visit the Access Keys page.

Once there, choose the scopes available to your access key. For this tutorial, you'll need the read:players and write:players scopes. Create your access key and copy it into the access_key field of the settings.cfg.

Creating your group

Talo players can have properties (known as props) that persist between sessions. As long as you know who the player is, you can set and get these properties. Player groups are able to read these properties and adjust the group's members accordingly.

To create your group, click the Services dropdown and go to Groups. Create a new group where you check for the online prop being equal to true. After creating your group you can pin it to your dashboard so you can see the online player count from the dashboard homepage.

Creating your player group in the dashboard

Setting up the game logic

All you need for this tutorial is a scene with a single root node, for example a Node2D. Attach a script to your root node with the following content:

extends Node2D

@export var username: String = "username"

func _ready() -> void:
  # prevent Talo from exiting before our online prop logic runs
  Talo.settings.set_value("", "handle_tree_quit", false)

  Talo.players.identified.connect(_on_identified)

  # identify who the player is
  Talo.players.identify("username", username)

func _on_identified(_player: TaloPlayer) -> void:
  # set the prop now that we know who the player is
  await Talo.current_player.set_prop("online", "true")

func _notification(what: int):
  match what:
    NOTIFICATION_WM_CLOSE_REQUEST:
      # update the prop before quitting
      await Talo.current_player.set_prop("online", "false")
      get_tree().quit()

This script does the following:

  1. Sets the Talo handle_tree_quit property to false. By default Talo will listen for the NOTIFICATION_WM_CLOSE_REQUEST notification to run cleanup operations and then exit. However in this case, the online property should be updated first before the game exits.
  2. Identifies the player using the username service. The player's username can be customised using the export variable.
  3. Once the player is identified, their online property is set to true. At this point they should be in the "Online players" group you created earlier.
  4. If the player closes the game, their online property is set to false and the game is exited. They will no longer be part of the "Online players" group.

Testing the online player count

You can now open your game, go to the dashboard, and see the "Online players" group count is 1. If you close the game, it will reset back down to 0. As mentioned earlier, the group can be pinned to your dashboard so you can always see the online player count when visiting the Talo dashboard.

Pinned online player count in the Talo dashboard

Making oversight easy

Talo is designed to be extremely flexible in the way it provides observability and oversight to you. You don't need to spend hours building your own tools when you can just use Talo and the customisable groups to drill down into specific player behaviours.

If you're building a game and you want more oversight over it, come and join our Discord community or follow us on GitHub to keep up to date with how we're improving Talo to make game development fun, easy and observable.


TudorWritten by Tudor

Build your game faster with Talo

Don't reinvent the wheel. Integrate leaderboards, stats, event tracking and more in minutes.

Using Talo, you can view and manage your players directly from the dashboard. It's free!

Get started

More from the Talo Blog

Levelling up your game with Talo’s Player Groups
5 min read

Levelling up your game with Talo’s Player Groups

Learn more about all the ways to segment your players and understand them better with Talo’s powerful group filtering system.

Changelog: New group filtering + interactive Playground
2 min read

Changelog: New group filtering + interactive Playground

Catch up on Talo’s November 2024 updates, including a more interactive Playground, new group functionality and arm64 support.

Exploring Talo’s new Caddy self-hosting template
3 min read

Exploring Talo’s new Caddy self-hosting template

A breakdown of Talo’s latest Caddy-based self-hosting option, plus a look at other self-hosting templates available for your game.

Changelog: group updates + new Godot game save demo
2 min read

Changelog: group updates + new Godot game save demo

All the highlights from Talo’s October 2024 releases across the dashboard, backend, Godot plugin and Unity package.