Dear all,
I'm receiving some data from a sensor tool and need to draw the data as it arrives. I just need a normal graph, basically, that inserts points whenever it receives a new data point from the sensor tool.
I have a working solution, but it's incredibly slow. I solved it by adding the new point to a Queue every time one arrives, then updating a Texture2D (1600x200) with the contents of the Queue afterwards, then calling Texture2D.Apply() to upload the texture to VRAM, then assigning the texture to a GUI.Box.
I'm getting a ridiculous drop in framerate when the graph is active, though, especially after it has run for a while. I'm not surprised at all, I know it happens because:
- I need to clear the texture every time to make sure it isn't drawing data in outdated positions when the graph scrolls
- The calls to SetPixels get expensive when the Queue reaches max length (= width of the texture = 1600 data points)
- Texture2D.Apply() is severely limited by bus bandwidth is should never be called continuously in this manner in the first place.
I know I can probably get around these things by defining the graph as a collection of Vector2, and then use RenderTexture to have the graphics card render them to a texture for me. That would save me the call to Apply, right? Problem is, my company hasn't invested in Unity Pro yet. :( So I don't have access to RenderTextures.
Does anyone know of a solution I can use in the meantime that won't destroy my performance?
Thanks a lot in advance,
Christian
EDIT:
This is a follow-up to finalize the question and show that the solution worked.
I went with the LineRenderer solution proposed in several of the answers. This is what the graph looks like now:

Nevermind the white bars; they’re part of the skybox which is visible because the graph is transparent. The little red dot is a Time-indicator. You can go back in time and look at data that got recorded previously, it just shows where on the graph you are. This was implemented with a LineRenderer and a small sphere for the red dot, put in a layer on its own and rendered with an orthographic camera that culls everything but that layer. It has virtually no impact on performance. This question can be closed, now. ![]()