Skip to content

Simple plugin to interact with twitch IRC and pubsub from Unreal Engine 5

License

Notifications You must be signed in to change notification settings

zeplin455/TwitchInteractionUE

Repository files navigation

TwitchInteractionUE

Simple plugin to interact with twitch IRC and pubsub from Unreal Engine 5

About

This plugin adds some C++ code and components that can be used to send and receive twitch chat messages, chat commands and received twitch bits/redeem/subscribe notifications. The plugin was built in UE5 Early Access but is also compatible with UE 4.27, The example blueprints are just invalid in UE4.

Getting Started

Add the plugin to your project by creating a plugins folder in your project root and adding the contents of this repo into a TwitchInteractionUE folder in the plugins folder. (The repo is structured so that it can easily be pulled into your plugins folder as a git submodule)

image

Then go to your project plugins menu and activate it.

image

Unreal will ask you to restart after which the plugin will be active.

In the plugin content folder there are example blueprints showing the basic setup and usage of the components.

image

When creating a blueprint using this plugin, there are 3 components tha can be used.

image

Twitch setup

First of all you need to register your app on twitch. For this you can go to dev.twitch.tv/console. Under applications click "Register your Application". Then fill in the details as you like but the important part here is that the redirect URL is a localhost address that matches the plugin URL (Will be covered later). It defaults to http://localhost:8080/Auth but can be changed as long as it follows the pattern of http://localhost:{port}/{something}. This is where twitch will redirect the browser to for token delivery everytime the app needs to authenticate. Also make a note the Client ID given to you by twitch after registering you app. You will need it for the authentication token in Unreal Engine

image

Twitch Authentication Component

The Authentication component handles the protocol of getting an authentication token from twitch which is used to login to either IRC (Twitch chat) or pub sub (events).

Twitch requires a user to confirm access to a new application on twitch's website and this confirmation then redirects to a url to deliver the authentication token. To facilitate that process, the twitch authentication component will run a local webserver that twitch can redirect to.

The plugin will open a browser window that connects to twitch to fetch a login token/confirm app access if needed and the browser will be redirected back to point to the internal webserver to deliver the token to the component.

This component has values that can be set directly or through blueprints but they are the following:

image

The redirect and listen port needs to match what you setup in twitch (see above twitch setup) and needs to be localhost. The Client Id needs to also match what was given by twitch from the above setup. Username should be your username that you will use to log the app in on twitch. The Userid and token can be left blank because they will be retreived on login. The default scopes should work for most scenarios but if you want to change them you can lookup scopes and what they do on https://dev.twitch.tv/docs/authentication#scopes

You can connect an Pubsub component or Chat component or both in the construction script/begin play of your blueprint so the Authentication component can populate important variables for their use upon login.

image

There are these events that you can bind to and handle accordingly.

image

See the example blueprints for a full login flow as well as saving the token to avoid having to login everytime you start when you still have a valid token.

Twitch Pub Sub

This component connects to twitch pub sub to listen for these events:

  • Someone used bits.
  • Someone received a new bits badge.
  • Someone used a channel point redeem.
  • Someone subscribed to the channel.

After authentication you can connect this component and listen in the simplest form like this:

image

The events can be bound to in blueprints like this.

image

image

image

image

image

Twitch Chat

The twitch chat component can send and receive chat messages as well as listen for chat commands and react to them. After authentication the simplest form to connect it would be something like this:

image

It has the following events you can bind to in blueprints:

image

Every message comes with a lot of detail around it:

image

To listen for commands you can register a command in the component you want to listen for like this:

image

With this example if someone types "!patpat" in chat then it will fire the following event bound to it in Unreal engine:

image

Options received would be part of the command like for example "!patpat 50". <- here the 50 is an option that will be given in the Command options array of the event when it fires and you can define how you want to handle that. The characters that defines a command and the option separator can be customized in the component as well (It defaults to ! and a space):

image

Sending a message can be done with the Send Message Node: image

The send message bool is poorly named but is WIP to deal with private messages but you can leave it checked for now and I'll update this section when its updated.

About

Simple plugin to interact with twitch IRC and pubsub from Unreal Engine 5

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published