Unreal quick tip: Simulating Cable Components in local space
Ever needed to have a Cable Component attached to a moving actor? Chances are it looked like this:

This is because the cable is simulated in world space; as the cable moves through the map, it’s as if it is constantly whipped with great force.
Luckily, it’s very easy to get the cable to be simulated locally. We do need to add a tiny bit of C++ code for this to work though, but don’t run off screaming if you normally wouldn’t touch code with a 10 foot pole. There’s no Blueprint alternative, and it really isn’t all that scary.
Just in case you’ve never added C++ to UE4: install Visual Studio Community 2017 with these packages.
Once that’s set up, go File > New C++ Class…, select “Show All Classes” on the right, search for CableComponent, and click Next. Enter “LocalCableComponent” as name, and add “\Components” to the path.

Once Visual Studio loads up, take a look in the LocalCableComponent.h file. You’ll see this line: class YOURPROJECTNAME_API ULocalCableComponent : public UCableComponent . Copy the “YOURPROJECTNAME_API” to someplace safe, we’ll need it in a moment.
Now, replace LocalCableComponent.h’s contents with this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "CableComponent.h" #include "LocalCableComponent.generated.h" /** * */ UCLASS(hidecategories = (Object, Physics, Activation, "Components|Activation"), editinlinenew, meta = (BlueprintSpawnableComponent), ClassGroup = Rendering) class YOURPROJECTNAME_API ULocalCableComponent : public UCableComponent { GENERATED_BODY() public: virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override; protected: FVector _previousWorldLocation; }; |
All we’re doing here is marking that we want to override the component’s tick, and declare a Vector variable. This is also where you’ll have to copy the PROJCETNAME_API you safely copied earlier back in to place, otherwise your code won’t compile.
Next up, LocalCableComponent.cpp:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// Fill out your copyright notice in the Description page of Project Settings. #include "LocalCableComponent.h" void ULocalCableComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) { if(!_previousWorldLocation.IsZero()) { ApplyWorldOffset(GetComponentLocation() - _previousWorldLocation, false); } Super::TickComponent(DeltaTime, TickType, ThisTickFunction); _previousWorldLocation = GetComponentLocation(); }; |
This is all that’s required to get the cable to simulate in local space: each tick, we add the delta world movement to all cable particles. ApplyWorldOffset()
is already implemented in Unreal’s UCableComponent, it’s just not called from anywhere.
Save both files, hit compile in Unreal, and start using the component! Here’s a comparison:

Leave a Reply