Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Question C# code equivalent of actions in the scene.

Discussion in 'Scripting' started by petejames666222, Apr 12, 2023.

  1. petejames666222

    petejames666222

    Joined:
    Feb 22, 2023
    Posts:
    2
    Hi, everyone,

    I was wondering if Unity has the equivalent feature of Blender that outputs Python code corresponding to the actions you execute in the 3D viewport. For example, in Unity, is there a way I could view the equivalent C# output when I add a cube, or scale a cube for instance? Thank you.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,946
    Oh wow that would be really neat!!!!

    There isn't anything, but all of it can be done in code.

    You can make stuff with GameObject.CreatePrimitive(), but that already comes with everything put together.

    You can rotate stuff with direct calls on the Transform, such as the simple Rotate(), or the more-versatile RotateAround()

    If you want examples of creating stuff in code, I do have a handy repo of reference snippets that I call MakeGeo.

    For instance, this code makes a cube vertex by vertex and triangle by triangle, then adds and connects everything together:

    https://github.com/kurtdekker/makegeo/blob/master/makegeo/Assets/makecubes/MakeCube.cs

    This makes a sphere:

    https://github.com/kurtdekker/makegeo/blob/master/makegeo/Assets/makeuvsphere/MakeUVSphere.cs

    The latter was patterned after the Blender3D UVSphere

    MakeGeo is presently hosted at these locations:

    https://bitbucket.org/kurtdekker/makegeo

    https://github.com/kurtdekker/makegeo

    https://gitlab.com/kurtdekker/makegeo

    https://sourceforge.net/p/makegeo
     
  3. petejames666222

    petejames666222

    Joined:
    Feb 22, 2023
    Posts:
    2
    Good heavens! I didn't expect an answer so quickly.

    Yes, it would be very neat like you said. And in all fairness, I would say that this feature is probably more critical with Blender. The Blender Python API is quite challenging, at least for me anyway. Python itself is not particularly difficult. Just the way it is implemented in Blender.

    The reason I desired this feature in Unity is because with Blender, the lines of code are output like magic as you create and manipulate objects on the screen. I mean, it even outputs lines of code when you do things like extrude a part, and connect nodes to one another. Granted lines of code are not generated for everything, but it is still very useful.

    I had already done some simple coding in Unity, including things like adding primitives to the scene and all that. However, I have some ambitious projects in mind, and I am looking for tutorials that will address the topics required to bring the projects to life.

    Thank you so much for the links you provided. I will explore them all. And thank you again for your fast response.
     
    Kurt-Dekker likes this.