Unusual Unit Slowdown
My hobby project for a while is a little rts just to learn some programming, yesterday I added gl.lines to draw movement arrows from the unit to its end position, and I figured it out and got it working.
However, I went to test it and it works fine, but it seems when I send several units & they get in close proximity(seems like that is when the error happens at least), they lose like 90% of their speed and it seems like the game is lagging to death, running at ~400-900fps. At first their were two errors the speed loss and the gl.lines would noticeably turn off and on cycling through units, but I fixed that by adding some generic lists to the script on the camera to hold the unit#, source&dest x,y,z; so the OnPostRender() would never not have the unit's info to not render the line it just updates it when the unit's move method sends it (7 list later). The strange thing is that if I comment out of line on the unitScript to call the gl script the units move around perfectly(no error). I have tried messing with the gl script to the point of commenting out everything but an empty void OnPostRender() and two other methods(also commented out inside) with no global variables saved and when I ran the game with the unitScript line not commented out I get the same unit speed loss I get when I am drawing lines. I am clueless at this point what the problem might be.
Notes: None of the units have colliders, cast/receive shadows, the unit's move method is a coroutine that properly ends at destination & ends & re-creates if unit is sent elsewhere, the units speed is calculated by a speed * deltaTime(so if the game is lagging the unit should just jump further each step), and when this error occurs it doesn't recover and it effects every unit in the game until I restart it.
While I haven't found a permanent solution I have somewhat worked around the issue, because by using the list on the script that holds the information until it is updated again I was able to add a simple float timer that limits the update script to once every 0.1 seconds which reduces the lag-like effect a bit.
Note: I have been testing with only like 3-5 units. When I put 14 units on screen for another piece of code testing, this exact issue reappears.