1 Control Unity from Python WITHOUT mlagents
Вставка
- Опубліковано 24 січ 2023
- I wanted to control Unity from Python. So I wrote a free opensource library called Peaceful Pie. In this video, I show you how you can call functions in your Unity application from Python. We'll send strings and floats and data class objects. In both directions!
The project at the end of this video will look a little like github.com/hughperkins/peacef...
Peaceful Pie library is here: github.com/hughperkins/peacef...
Full playlist: • Control Unity from Python - Наука та технологія
Nice video! helped me a lot! please continue doing this tutorials, how to deploy the api listened in the port 9000 and how to export the 3d model please.
Thank you so much for the content. It's probably a very naive question but will users have to have an already installed version of python on their system once deployed?
So this isn't really targeting building deployable games. It's targeting using unity for research into reinforcement learning. You are right that if you want to use rl to train an ai for a distributable game, you will yes need to use mlgents or similar. I guess I should make this clearer now that you mention it.
@@rlhugh got it! I’ve played a bit with gym and I can see how it can be exciting to have unity based environments to explore beyond the scope of mlagents. Thanks again for the very informative video!
How can I execute a method every frame or at a fixed frame rate? I need to retrieve the position of a character every frame.
there's some discussion of controlling time in the second video ua-cam.com/video/p34dOZ6fcqg/v-deo.htmlsi=S4XhbmC5mLX_ItXa Not sure to what extent that answers your question?
Does Peacefulpie only support python 3.10?
I'm afraid 3.10 is going to break older projects depending on it since there were many changes from 3.8 to 3.10
I can make it work with 3.8. I just need to change typing from list to List basically. I can look into doing that. I'm not aware of any deep fundamental reason why 3.8 won't work. Will take a look. Thank you for the question!
there aren't huge difference between the two versions , just some older packaes doesn't support the 3.10 version , I'd just reccomment people just to install both versions and use ```update-alternatives --config python
``` to swap them
Released v2.1.0, which supports python 3.8 upwards, github.com/hughperkins/peaceful-pie/releases/tag/v2.1.0
@@rlhugh Amazing !
Hey i wanted to send masked image from a webcam using python only as that code is doing many things more so i am left with only this option to send image from python to unity can u help me with that
I mean, worst case, encode the image as base64, and send as a string.
hmm i get an exception when I try to run the python say.py --message hello command line.
peaceful_pie.unity_comms.CSException: The method does not exist / is not available.
Hello friend, I really liked your RL series, it helped a lot with my academic work. But I would like to know if it is possible to add peaceful-pie support to Python 3.7 as that would help me a lot. Thank you very much anyway and congratulations!
I'm not planning on doing that. You could probably modify the code to remove the 3.8 stuff. But why not install pyenv, and upgrade to python3.8?
@@rlhugh I ported the entire project and it worked well, thanks friend.
Great!
After following the tutorial, I get to the point where we test "say.py." When I run the command and pass in a message argument, it continuously spits out: "requests.exception.ConnectionError => ignoring, retrying." Any clue what this means? Thanks!
It means the server is not running. Are you running the unity application?
Note: it might be easier if you raise your issue on the peaceful pie github repository, as a new issue, since more space to ask clarifying questions etc there. Obviously the downside for me is that doesnt contribute to comment activity on my video :D But if that solves your issue better then I think it could be a good choice :)
thank you so much for answering this guys question, i got worried i did something wrong but all i did was forget to run the unity world@@rlhugh
what's the difference between this method and just using python sockets?
well, ultimately it does just use sockets. But it also handles converting objects to and from wire protocol. It handles converting a method call in python into a method call in c#. It's not hugely complex (it's not much code. You can see the repo). In fact, originally I was going to do a video where we just create the entire code together. But at some point, the error handling and retry logic became a bit too complex to put in a video, so I put the code into a library instead, and made the video about how to use that library, without having to code it all yourself
Is there a way to use peaceful-pie to start the Unity game? My understanding is that the Unity game needs to be running before we run the python script. Is there any way the python script can initialize it (ie basically pressing the Play button)?
Easiest would be to make a standalone unity player, and run that, eg using subprocess
@@rlhugh Do you know of any examples/tutorials of how to do this by chance? Thank you!
Yeah, you can take a look at github.com/hughperkins/peaceful-pie/blob/fb8b0bada72102d32c9247fbf3074573c48704e5/examples/DungeonEscape/python/rl1.py#L29
That might be overkill. You can use that code to spawn multiple unity instances in parallel :)
I was using this to run training on aws gpu instances
i cant use your DLL files
What are you trying to do, and what happens when you try to do that?
@@rlhugh I have downloaded the dll files(AustinHarris, peaceful pie) you given in the github. But, it is in CR download format and not opening in Unity.
What is CR format? If you mean
vs
, These are binary files, and should not be affected by line feed format I think?
nice content ! I would like to suggest a video content for you maybe if you be interested in , and I would like to see it a lot. Making a game content using gpt-3 engine and unity .
Definitely a fan of playing with gpt3. My video with the most views is a chatgpt video in fact. Don't suppose.. thoughts on the simplest game you can think of that would use gpt3 and unity, and you'd be interested in watching a video about?
Just like a generic example of typing a message in unity, and getting a reply back from gpt3 perhaps?
(thoughts on latency? Since peaceful pie as it currently stands has Unity as the server, and python as the client, the simplest approach could be to poll unity from python. Maybe like once a second?)
Actually, we can probably call the gpt3 endpoint directly from c# unity. Your preference on going directly from c#, versus going via Python?
yes exactly. I want to see basic implementation gpt-3 logic with gaming. It could be simple game or anything. I couldn't figure it out what the content could be. May be a real time npc chat generation or something effects gameplay. :)