Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

weacw/Basic-Unity3D-Python-server

 
 

Repository files navigation

NEWER APPROACH

This project served as a way to connect Python with Unity 3D. However, in my current project (https://github.com/NumesSanguis/FACSvatar) I switched to ZeroMQ for this, which is more stable and more robust than the code found here. So I would recommend looking at that code.

Basic-Unity3D-Python-server

A Python 3.6 client with asyncio for asynchronous execution, that can send to and receive JSON messages from a Unity3D server (Unity 2017.2.0f3).

How to run

Test usage Unity 3D - Python client

  1. Start Unity 3D from BasicUnityPython & press play (you should see in Unity: Server is listening)

  2. Open terminal in this folder and run: python client_asyncio.py, you should see in Unity: "Hello World x" / Python terminal:

    Send: {'welcome': 'Hello World x!'} Received: {'unity': 'Unity sends its regards x'} Close the socket

Test usage Python server - Python client

  1. Open terminal in this folder and run: python server_asyncio.py
  2. Open another terminal here and run: python client_asyncio.py

Test usage Unity 3D - Python with SocketIO

  1. Start Unity 3D from BasicUnityPython_aiohttp & press play
  2. Open terminal in this folder and run: python client_asyncio_aiohttp.py (you should see in Unity: "data_stuff": x / Python terminal: message: {'receive': 'received x'})

To setup in your own project (asyncio, not SocketIO)

Notes

Communication over SocketIO is inspired by tawnkramer/sdsandbox (https://github.com/tawnkramer/sdsandbox/tree/master). However SocketIO (both the original with FLASK and modified with aiohttp) was found to be way slower.

Measured with a phone stopwatch for 10 seconds:

  • Just asyncio: 7738 messages received from Unity
  • asyncio with SocketIO and aiohttp: 97 messages received from Unity (seems to be faster than no asyncio with FLASK)

Therefore simple asyncio about 80 times as fast with this unprofessional measurement.

About

A simple Unity 3D server - Python asyncio client over TCP example

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.5%
  • Python 0.5%
Morty Proxy This is a proxified and sanitized view of the page, visit original site.