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. Dismiss Notice

My script makes game slow. Why?

Discussion in 'Scripting' started by danielapix, Feb 26, 2015.

  1. danielapix

    danielapix

    Joined:
    Feb 15, 2015
    Posts:
    7
    I have got a tunnel in which I want to create some obstacles with various and random rotations and positions just on X and Y axes. To do that, I don’t need an upgrade by frame, so these instructions are processed only in the very first one. But it makes me a problem: the game is very slow as it’s running very hard operations and the computer is going to be in crash. When I disable the script, it works correctly without any problems. Why does it do that?

    The script considers the coordinates of the tunnel’s components. For some reasons, I have had to create the obstacles by two points whose coordinates are encompassed by it’s elements.

    This script is not used as reference in other scripts.
     

    Attached Files:

  2. ADNCG

    ADNCG

    Joined:
    Jun 9, 2014
    Posts:
    989
    how many obstacles are you iterating through, and is there a reason why the number of obstacles is declared as a float rather than an integer?
     
  3. danielapix

    danielapix

    Joined:
    Feb 15, 2015
    Posts:
    7
    Yes, problem is the number of obstacles. But these are very simple and it sounds a little strange it gives crash only with 10 obstacles spawned in the scene. That's why I'm suspecting about some useless calculations or something like this. Regarding the float, I'm working again on this script, so first I want to solve the single problems to not make even more complicated the examination, and then getting the script optimized. So the type float doesn't make any sense and int works correctly.

    When I created the object without interpolation, I could have 40 obstacles with no crash. Is the method Lerp in class Quaternion to be too much complicated? Because I need two points of the object to calculate another one to establish a translation on the same axis outside the tunnel, considering it like a function, and I have no idea to fix it else. Have you got any advice?
     
    Last edited: Feb 27, 2015