methusalah / SplineMesh

A Unity plugin to create curved content in real-time with bézier curves
https://twitter.com/dumas181
MIT License
1.05k stars 104 forks source link

[Question] SplineMeshTiling misses deleting some segments. #44

Closed brightest1102 closed 3 years ago

brightest1102 commented 3 years ago

SplineMeshTiling misses deleting some segments.

Hi,

I 've using this amazing script for weeks and it helps me a lot. Then found that some segment will not be deleted when switching curve space to non-curve space.

I think it come from the following scripts.

SplineMeshTiling.cs

    // we destroy the unused objects. This is classic pooling to recycle game objects.
    foreach (var go in generated.transform
        .Cast<Transform>()
        .Select(child => child.gameObject).Except(used)) {
        UOUtility.Destroy(go);
    }

Casue the children changes after the during the 'foreach' iteration. One segment needed to be destroyed will be skiped in every two iteration.

Using backward iteration from the original IEnumerable list. Or simply add ".ToList()" , making it a saved list may solve this problem.

SplineMeshTiling.cs

    // we destroy the unused objects. This is classic pooling to recycle game objects.
    foreach (var go in generated.transform
        .Cast<Transform>()
        .Select(child => child.gameObject).Except(used).ToList()) {
        UOUtility.Destroy(go);
    }

Thanks.

methusalah commented 3 years ago

I can reproduce the issue, and it seems that your fix is ok. thanks !