Bug Symptom:
When a cable attached to 2 actors with both ends, and both 2 actors move long distance by setting location, the cable component will sometimes disappear. (This bug seems to occur more often when a cable has more segments, ex: segments > 12)
Bug Cause: When this bug occurs, printing out the location of each particle of that cable, I get this:
LogGamePlay: C++ CABLE_DEBUG_TEST() particle index: 0 x: -284895.406250 y: 120371.539063 z: 111.272942
LogGamePlay: C++ CABLE_DEBUG_TEST() particle index: 1 x: -nan(ind) y: -nan(ind) z: -nan(ind)
LogGamePlay: C++ CABLE_DEBUG_TEST() particle index: 2 x: -nan(ind) y: -nan(ind) z: -nan(ind)
LogGamePlay: C++ CABLE_DEBUG_TEST() particle index: 3 x: -nan(ind) y: -nan(ind) z: -nan(ind)
LogGamePlay: C++ CABLE_DEBUG_TEST() particle index: 4 x: -nan(ind) y: -nan(ind) z: -nan(ind)
LogGamePlay: C++ CABLE_DEBUG_TEST() particle index: 5 x: -nan(ind) y: -nan(ind) z: -nan(ind)
LogGamePlay: C++ CABLE_DEBUG_TEST() particle index: 6 x: -nan(ind) y: -nan(ind) z: -nan(ind)
LogGamePlay: C++ CABLE_DEBUG_TEST() particle index: 7 x: -nan(ind) y: -nan(ind) z: -nan(ind)
LogGamePlay: C++ CABLE_DEBUG_TEST() particle index: 8 x: -nan(ind) y: -nan(ind) z: -nan(ind)
LogGamePlay: C++ CABLE_DEBUG_TEST() particle index: 9 x: -nan(ind) y: -nan(ind) z: -nan(ind)
LogGamePlay: C++ CABLE_DEBUG_TEST() particle index: 10 x: -nan(ind) y: -nan(ind) z: -nan(ind)
LogGamePlay: C++ CABLE_DEBUG_TEST() particle index: 11 x: -nan(ind) y: -nan(ind) z: -nan(ind)
LogGamePlay: C++ CABLE_DEBUG_TEST() particle index: 12 x: -283573.937500 y: 120196.406250 z: 266.018738
Except for the start and end of the cable, all the particle positions are all undefined. Which leads me to suspect
a potential bug in this function:
static void SolveDistanceConstraint(FCableParticle& ParticleA, FCableParticle& ParticleB, float DesiredDistance)
// Find current vector between particles
FVector Delta = ParticleB.Position - ParticleA.Position;
//
float CurrentDistance = Delta.Size();
float ErrorFactor = (CurrentDistance - DesiredDistance)/CurrentDistance;
If for some reason ParticleB.Position = ParticleA.Position, then ErrorFactor will be undefined, and cause all the particles to have invalid values, except for !bFree particles (the end points of the cable)
Bug solution:
I simply add a small number to the CurrentDistance variable before dividing it:
// MYW modify bgn
//float CurrentDistance = Delta.Size();
float CurrentDistance = Delta.Size() + 0.01f;
// MYW modify end
This is only my suspicion, I will be glad if an Epic staff can comment on this problem and solution.
Thank you!