UE4 16.3 Potential bug in CableComponent.CPP and solution

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!

Yup, for me the cable never seems to appear in the first place. Using version 4.25.4

If I manage to find a fix I’ll be sure to post it here

For anyone else finding this, yes this is still an issue in 2021.

Do you mean you still experience cable disappearing in later versions of UE4? (ex: UE4.2x ??)

Since no one reply to my original post for a long time, I always thought I am the only one who encounters this bug.

thanks in advance!! :stuck_out_tongue:

Asked about this on UDN, got this response;
“Thanks for reporting this. A fix has been submitted and should be available in the next release.”

Hey!
Thank you for taking the action to notify Epic of this bug! :smiley: