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

Transform.localRotation performance

Discussion in 'Scripting' started by outis, Apr 22, 2013.

  1. outis

    outis

    Joined:
    Apr 8, 2013
    Posts:
    1
    I am in a situation where I have a complex machine with a number of moving axes that are governed by some external animation process. The machine is built up from rigid bodies. I need to move these axes to a certain position every frame: rotating axes for instance may be set to '45', meaning 45 degrees from its zero position.

    I'm currently doing this by altering the local rotation (using localRotation instead of localEulerAngles gives me the same trouble). In the following, position is the desired rotation of the axis at the current time.

    Code (csharp):
    1. axis.transform.localEulerAngles = zeroposition + position * Vector3.forward;
    Doing this 40 times in my scene causes the frame rate to drop from 96 to 6 fps. This surprised me. Eventually, I need to be controlling hundreds of axes.

    If I would do this in OpenGL, I would simply set the transformation matrices, and then go through the model hierarchically, applying the matrices to the OpenGL transform matrices. That should not cost much time at all. Does anyone know what happens in Unity when I change the localRotation? Is there an alternative?

    Any help would be greatly appreciated.
     
  2. Psyco92

    Psyco92

    Joined:
    Nov 15, 2013
    Posts:
    22