+1 vote

Hi everyone!

I am a student and work on machine learning, especially reinforcement learning. I want to use Godot as environment instead of Gym (https://gym.openai.com/ ) because I want to make a little bit complex scenarios.

Is there a way to communicate Godot with a Python script? I mean, I take the screen data, some sensor datas (distance to road lines and other cars for example) from the game and process them in python script with machine learning libraries and send some actions (go ahead, steer, slow down etc.).

Thanks in advance.

asked Aug 14 in Engine by Parjina (54 points)
edited Aug 14 by Zylann

1 Answer

+1 vote
Best answer

There is a Python binding for Godot: https://github.com/touilleMan/godot-python but I don't know if it will work with the libraries you are using.

An alternative would be to make your Python system and Godot communicate with network, shouldn't be too bad for local use and it's a pretty good solution to make so wildly different systems work together.

Another way is to use the C# version so you can embed IronPython and use Python under that (far fetched hehe) but similarly it might not work depending on your libraries.

Another alternative would be to do it all in GDScript or compile Godot in C++ with the libraries if they have a C API instead of Python.

answered Aug 14 by Zylann (18,389 points)
selected Aug 14 by Parjina

Thank you Zylann!
I will consider all of them. But first and second ones seem more applicable for me =)

Hello! I am also interested in your ideas.
I never understood what I have to do to make the python bindings work with Godot. I downloaded the bindings via the asset library, but I don't know what to do next. Is there a tutorial?

As for the second option, I also don't know where to stay from. Is there any easy to use high level api for network communication? I wouldn't like to reinvent the wheel.

I never used the Python binding, I just know it exists^^

As for the second option, you just need to be familiar with networking in Godot and Python. You'd open a socket (TCP maybe) to connect the two ends together. Either of them can be server, the other client. I'm sure Python has modules for that, and Godot has TCP classes exposed to GDScript.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.