Search Unity

Place objects via Python code

Discussion in 'Scripting' started by Moroh209, Apr 12, 2022.

  1. Moroh209

    Moroh209

    Joined:
    Apr 12, 2022
    Posts:
    5
    Hi guys I am a beginner in Unity3d.

    For now i want to place simple objects (e.g. Cubes) with a Python script.
    My Python program prints Vectors like the follwowing: (x, y , r) r = rotation
    (The height z is always 0)

    Is there any way to place Objects automatically based on the resulting Vectors of my Python program?

    Greetings! :)
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
    You'd have to do something like write your vectors to a file in python, then read the file in Unity to place the cubes. Really it'd be much simpler to just rewrite your python script in C# within Unity.
     
    Joe-Censored likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    What are you using? Any Python external to Unity will require what PraetorBlue says above: you would need to write C# code in Unity to digest the output from a file your Python program writes, which makes it silly: just learn C#.

    Alternately there is a Python module available in Unity for Editor-only use:

    https://docs.unity3d.com/Packages/com.unity.scripting.python@2.0/manual/index.html

    Disclaimer: I have not used it.
     
    Last edited: Apr 12, 2022
    Joe-Censored likes this.