Updatable LinesMesh, can't add or remove points

I’m attempting to draw a line through some points in 3D space with a little ball along each point. The set of points should be fully updatable.

I can update the points of a LinesMesh to move them around, but adding or remove points does not work as expected. Old line segments do not get removed, nor do new ones appear.

As the doc says:

* When updating an instance, remember that only point positions can change, not the number of points

If the number of points change, you must recreate the line system.

You can also try to create the line system with the maximum number of points you will have and define the same coordinates for all the last points of the array.

1 Like

Thank you. Which document are you referring to? I didn’t come across it.

My first implementation actually did this, unfortunately even though I .dispose()d my LinesMesh before making a new one, I saw heap usage grow by several megabytes each time around (for a LinesMesh of a handful of points plus the same number of Spheres) without going back down. Since the mesh needs to be updated quite frequently, this quickly led to crashes.

It is the documentation of the options parameter of the CreateLines function:

Recreating a new LinesMesh should not leak memory, as long as you dispose the previous one: are you able to reproduce this behavior in the Playground?

1 Like