paint-brush
Must-Have Real-Time Functionality for Your Unity Gameby@pubnub
215 reads

Must-Have Real-Time Functionality for Your Unity Game

by PubNubAugust 31st, 2023
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

The best way for any game to improve player engagement & retention is to integrate real-time interactivity & a Unity SDK helps you do it quickly & efficiently.
featured image - Must-Have Real-Time Functionality for Your Unity Game
PubNub HackerNoon profile picture

The best way for any game to improve player engagement and retention is to integrate real-time interactivity; this means features like in-game chat, alerts, leaderboards & presence (whether a player is online or offline), but developing these features yourself can be time-consuming and distracting - time you could spend better improving other aspects of your game.


With the use of a Unity SDK, developers can take advantage of modern development practices to quickly add interactive features to their games, such as:


  • Player chat: Whether it is global, within a lobby chat room, or a direct whisper, you can exchange messages or emoji reactions reliably and at scale.  With a history of all messages sent, you can help newly joining gamers catch up and better understand your community with analytics.
  • Social features: Friend lists help build a community around your game, and features such as user presence help you determine whether players are online or offline.
  • Leaderboards & Challenges: Track progress for the whole global community, per region, or just amongst a few teams.
  • Profanity filtering & translation: Promote a global community of players with automatic translation of messages but moderate those engagements in real-time with language and sentiment analysis to discourage negative behaviors.
  • Multiplayer game updates: Exchange player movement and status with all game participants, creating a performant multiplayer experience.


Now, we’ll get into more detail about these features and give a high-level look at the technology behind them.

Player chat and messaging

Being able to exchange messages with other players is fundamental to any gaming community, and one very popular architecture to implement chat is publish & subscribe.  In short, participants use “channels” to exchange messages; players publish messages on a channel, and other users subscribe to that channel to receive those messages. Sending a single message on a single channel is fine, but the channel mechanism can scale to whatever size is needed.


But it goes beyond just your basic sending and receiving of messages. For player chat and messaging, there are other features to consider:


  • Message Persistence- Using a Message Persistence API lets you catch up on messages previously sent to a channel. Hence, players joining mid-way through a conversation have the context or for archival purposes. A dedicated ‘MessageCounts’ API also returns the number of messages received since a player was last active.


  • File Sharing- File sharing lets users to exchange more than just text data, with storage in the cloud allowing players to send images or audio as part of their messages.


  • Message Reactions- After sending Messages, many use cases involve adding metadata to those messages, which is adjustable with the Message Reactions API.  Most commonly, you can specify a reaction such as 👍 or 🎉 but also use the API to perform “soft edits” of a message and add message threads.


  • Emoji- Most messaging systems aren’t limited to text strings. For example, during a game, if one player wants to send a smiley face 🙂 the other players will need to know who sent the message, what emoji they are sending, and some other metadata, such as a message ID. You don’t need the same guaranteed service of delivery with emoji compared to messaging, so a “fire and forget” API is ideal for this kind of short-lived message with less network overhead.

Social features

Adding social features to your game is the most effective way to foster an active and emotionally invested player community.


Having a list of friends, knowing when they are online, and allowing profile personalization are all expected features of any multiplayer game. However, they can be challenging to implement at scale - unless you use a platform solution that allows for integration with third-party services.

Player Presence

A Presence API can determine a user’s online presence.  When users subscribe to a channel, they are considered present on that channel, so each channel has its presence indication, and the system is flexible enough to allow you only to register to receive presence changes on specific channels.

Friend List

A Channel Group keeps track of your friends and their online or offline status. Channel groups allow developers to bundle thousands of channels into a single group that can be subscribed to but not published to (you need to publish to the individual channels).


By grouping all the private channels of any user’s friends, the presence of those friends can be retrieved efficiently. When adding a new friend, their private chat channel is added to the channel group representing the player’s friends, and we can register to receive presence notifications for that created group.

Leaderboards & Challenges

Leaderboards can add challenge to your game and extend its lifespan, fostering competitiveness amongst your player base. Many games add challenges and achievements to extend their replay value. Tracking and competing with your friend’s achievements is far more engaging than just grinding your achievements offline.


To create a leaderboard for any aspect of your game, you need a global view of all your player data; either you could have players submit their high scores or achievements to your custom backend and handle the infrastructure yourself, or you could make use of a third-party developer platform’s serverless functions to create and distribute your dashboard for you automatically. These functions capture events on the platform and allow you to write code to re-route, augment, filter, and take action on the message data.

Moderation & Translation

What’s better than having an awesome community form around your game? Probably having that community be global. But the larger your community becomes, the more important it is to ensure that player interactions can be translated in real-time, removing any language barrier between players and moderating to prevent abuse in all forms.


All of this is possible using the same concept as a leaderboard implementation. Specifically for translation and moderation, a function can be run to pre-process any message before it is sent, allowing us to modify any message before forwarding it to the intended recipients.

In Summary

With a few changes, you can improve your player engagement and retention by quickly integrating real-time features into your video game regardless of scale. PubNub helps streamline the development process for Unity developers. This way, developers can focus on exciting aspects of their game and let us handle the heavy lifting of online features. Sign up for a free trial today.