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 /
  • Help Room /
avatar image
0
Question by bbh1400 · Mar 17, 2016 at 08:28 PM · unity 5python

Python to C# script communication

So I have a C# script that communicates with a python script. The python script can only run at 15 cycles per second. This causes a bottleneck for me because the function I'm using to communicate with the python script is being called in Update(or so I'm assuming). In turn the game runs at 15fps. I'm trying to figure out how to call this function separate from update.

I have tried using co routines and invoke repeating, but both of them yield the same results. I'm assuming that I need to do something with threading, but I'm not quite sure where to go with it. Below is my current solution that doesn't run quite fast enough. Thanks for any help or pointers in the right direction.

 public  IEnumerator ConnectAsClient ()
     {
 
         while (true) {
             TcpClient client = new TcpClient ();
             client.Connect (IPAddress.Parse ("192.168.3.93"), 5004);
             NetworkStream stream = client.GetStream ();
             string s = "hello from client";
             string t = "second thing to send";
             byte[] message = Encoding.ASCII.GetBytes (s);
         
             String responseData = String.Empty;
             byte[] data = new Byte[256];
             // Read the first batch of the TcpServer response bytes.
             Int32 bytes = stream.Read (data, 0, data.Length);
             responseData = System.Text.Encoding.ASCII.GetString (data, 0, bytes);
             //    print ("Received: {0}" + responseData);
             recievedData = responseData;
             stream.Write (message, 0, message.Length);
             message = Encoding.ASCII.GetBytes (t);
             stream.Write (message, 0, message.Length);
             stream.Close ();
             client.Close ();
             yield return null;
         }
     
         //StartCoroutine (ConnectAsClient);
         //    print ("closed\n");
     }
 
     void Start ()
     {
         StartCoroutine ("ConnectAsClient");
     }
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by off99555 · Nov 16, 2018 at 10:31 AM

I know this thread is quite old but for anyone looking for a solution to communicate python with unity, please take a look at my repository dedicated for it: https://github.com/off99555/Unity3D-Python-Communication

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 Siliconifier · Dec 29, 2020 at 08:40 PM

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

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

77 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

Related Questions

Unity stops reacting randomly 0 Answers

Button object has no attribute OnClick 1 Answer

How to run python script in unity3D? 0 Answers

How to record 360 video during gameplay in unity? 1 Answer

Baked materials from blender cycles don't appear right in my scene? 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