Unreal Engine Socket Communication

0. Environment

Windows 10

Unreal Engine 5.1.1

SteamVR 1.25.8

1. Create a new Unreal project

Select "Film / Video & Live Events" -> "Blank". Leave "Starter Content" and "Raytracing" unchecked.

Click "Create" button.

2. Add plugin

Click "Edit" -> "Plugins" to open the plugins window.

Search and add the following plugin.

After adding the plugin, Unreal Engine needs to be restarted.

3. Set up a new GameModeBase class

Click the Blueprint button, select "New Empty Blueprint Class...".

Choose "GameModeBase" as the parent class.

Finally, update the GameModeBase class

4. External Python server

import socket
import struct

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("", 8080))
s.listen(1)

conn, addr = s.accept()

print("connected by", addr)

while True:
    data = conn.recv(1024)

    print("recv:", data)

    content = "hello Unreal!"

    buffer = struct.pack(">BB", 1, len(content))
    buffer += content.encode()

    conn.sendall(buffer)
    print("sent:", buffer)

    break

s.close()

A Note on FPS

Since we might want to use EventTick to transmit messages, it could be useful if we limit event tick rate on the gamemode base.

To set the rate, go to Blueprint setting of the GameModeBase, select "GameModeBase" on the Components view. Then, on the Details panel, change the "Tick Interval" value to desired value.

Last updated

Was this helpful?