Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by arlo24670 · Aug 19, 2018 at 01:39 PM · streamingpython

Sharing data between unity and python

I'm trying to send the status of a game object from unity to python. Therefore I create a text file in unity and insert my data into it and then I try to open and use the text file in my python file(this procedure goes on as the game runs). Obviously, I have a problem sharing this text file. Is there a better way to send data from unity to python? (In order to avoid streaming problems)

Thanks :)

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image troopy28 · Aug 19, 2018 at 06:36 PM 0
Share

How is your Python code run? Do you host it from Unity with a specialized library, or is it two separate processes? In what is the context do you use that?

avatar image arlo24670 · Aug 20, 2018 at 01:24 PM 0
Share

They are two separate processes. I gather data from my unity file and feed it to my python file(as input for my convolutional neural network).

@troopy28

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by troopy28 · Aug 20, 2018 at 04:01 PM

Files that are in your Unity editor, like textures, sound files, text files and so on are embedded in the Unity resources, thus not possible to access from another process (at least not easily). Moreover, they cannot be modified by the game once compiled.

If you want to share your data using a text file, you must create it using C#, with the standard .NET way, in a given path that your Python script would know.

But this is clearly not what you want here, since the status of the game will be always changing. If you share your data with the text file, you will likely run into issues like Python reading while you are writing it from Unity.


There are several ways to share data between processes:

  • Sockets, like you would do to share your data with a distant computer. The sole difference here is that the server and the client will be on the same machine. It's up to you to choose whether Unity is the server or the client, it depends on how your things work. See here.

  • Another way is to use anonymous pipes. These are well documented for the C# side, but not really on the Python side when it comes to Windows. See this if you are under Windows and want to use anonymous pipes.

  • Host your Python directly from Unity using a library such as IronPython, which allows a lot of interoperability between the host (C#) and the hosted scripts (your Python CNN).

    Regards

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by off99555 · Oct 29, 2018 at 07:54 AM

I've gone through a lot of trouble regarding this Unity-Python communication issue. I've tried a lot and eventually settled down to ZeroMQ approach.

See Getting Started section and clone my repository here. You are going to like it https://github.com/off99555/Unity3D-Python-Communication

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image HunterJay · Apr 15, 2019 at 04:09 AM 0
Share

Thanks for this, trying it now!

avatar image
0

Answer by Siliconifier · Dec 25, 2020 at 03:09 AM

This might be useful to others in the future. Have a look at this repo.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Chrubgamer · Jul 11, 2021 at 02:45 PM

I know i am a bit late but i wanted to share my thought for anyone strolling by this post just like i did.

While the options above are complicated a more simple way is possible, if you do not have to much data to handle. If you were to write the info you got with python to a Json file you could read this with unity.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

93 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

unity and databases 1 Answer

Streaming music 3 Answers

It is possible to start a streaming AudioClip not from the beginning ? 1 Answer

Asset Managing for Mobile Devices 0 Answers

Live Streaming on Android using Unity 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges