1 Control Unity from Python WITHOUT mlagents

Поделиться
HTML-код
  • Опубликовано: 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
  • НаукаНаука

Комментарии • 48

  • @guilhermerodriguesmartins9131
    @guilhermerodriguesmartins9131 Год назад +1

    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.

  • @fredericbaroz4930
    @fredericbaroz4930 Год назад +1

    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?

    • @rlhugh
      @rlhugh  Год назад +1

      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.

    • @fredericbaroz4930
      @fredericbaroz4930 Год назад +1

      @@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!

  • @seifmostafa58
    @seifmostafa58 Год назад +1

    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

    • @rlhugh
      @rlhugh  Год назад +1

      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!

    • @seifmostafa58
      @seifmostafa58 Год назад

      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

    • @rlhugh
      @rlhugh  Год назад +3

      Released v2.1.0, which supports python 3.8 upwards, github.com/hughperkins/peaceful-pie/releases/tag/v2.1.0

    • @seifmostafa58
      @seifmostafa58 Год назад

      @@rlhugh Amazing !

  • @dickdick-wu9fw
    @dickdick-wu9fw 2 месяца назад

    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.

    • @rlhugh
      @rlhugh  2 месяца назад

      there's some discussion of controlling time in the second video ruclips.net/video/p34dOZ6fcqg/видео.htmlsi=S4XhbmC5mLX_ItXa Not sure to what extent that answers your question?

  • @wesleyjunkins9458
    @wesleyjunkins9458 11 месяцев назад +1

    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!

    • @rlhugh
      @rlhugh  11 месяцев назад

      It means the server is not running. Are you running the unity application?

    • @rlhugh
      @rlhugh  11 месяцев назад +1

      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 :)

    • @iankengott7155
      @iankengott7155 8 месяцев назад +1

      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

  • @bencebob8055
    @bencebob8055 8 месяцев назад

    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.

  • @thepratyush0704
    @thepratyush0704 Месяц назад

    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

    • @rlhugh
      @rlhugh  Месяц назад

      I mean, worst case, encode the image as base64, and send as a string.

  • @xrmasiso
    @xrmasiso 7 месяцев назад

    what's the difference between this method and just using python sockets?

    • @rlhugh
      @rlhugh  7 месяцев назад

      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

  • @user-wj1dg1pk5w
    @user-wj1dg1pk5w 7 месяцев назад +1

    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)?

    • @rlhugh
      @rlhugh  7 месяцев назад

      Easiest would be to make a standalone unity player, and run that, eg using subprocess

    • @EntertainerPark
      @EntertainerPark 7 месяцев назад

      @@rlhugh Do you know of any examples/tutorials of how to do this by chance? Thank you!

    • @rlhugh
      @rlhugh  7 месяцев назад

      Yeah, you can take a look at github.com/hughperkins/peaceful-pie/blob/fb8b0bada72102d32c9247fbf3074573c48704e5/examples/DungeonEscape/python/rl1.py#L29

    • @rlhugh
      @rlhugh  7 месяцев назад

      That might be overkill. You can use that code to spawn multiple unity instances in parallel :)

    • @rlhugh
      @rlhugh  7 месяцев назад

      I was using this to run training on aws gpu instances

  • @MrRedfield
    @MrRedfield 8 месяцев назад

    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!

    • @rlhugh
      @rlhugh  7 месяцев назад +1

      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?

    • @MrRedfield
      @MrRedfield 7 месяцев назад +1

      @@rlhugh I ported the entire project and it worked well, thanks friend.

    • @rlhugh
      @rlhugh  7 месяцев назад

      Great!

  • @kkvishva2088
    @kkvishva2088 3 месяца назад

    i cant use your DLL files

    • @rlhugh
      @rlhugh  3 месяца назад

      What are you trying to do, and what happens when you try to do that?

    • @kkvishva2088
      @kkvishva2088 3 месяца назад

      @@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.

    • @rlhugh
      @rlhugh  3 месяца назад

      What is CR format? If you mean

      vs
      , These are binary files, and should not be affected by line feed format I think?

  • @gorkemka4061
    @gorkemka4061 Год назад

    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 .

    • @rlhugh
      @rlhugh  Год назад

      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?

    • @rlhugh
      @rlhugh  Год назад

      Just like a generic example of typing a message in unity, and getting a reply back from gpt3 perhaps?

    • @rlhugh
      @rlhugh  Год назад

      (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?)

    • @rlhugh
      @rlhugh  Год назад

      Actually, we can probably call the gpt3 endpoint directly from c# unity. Your preference on going directly from c#, versus going via Python?

    • @gorkemka4061
      @gorkemka4061 Год назад

      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. :)