I’m wanting to have a cable component that is attached on both ends to different parts of a a moving pawn. When said pawn moves at a decent speed the cables start spazzing out due to the motion. I would like to be able to run the simulation in component space so that this isn’t an issue. Is there a way for me to make this happen in C++ (I haven’t seen anything for it in BP yet, but I may have just overlooked it)
This is still the first thing that comes up when you Google this issue. I’ll leave this answer here for anyone else stumbling across it. Turns out it’s really easy to set the cable up to simulate locally. The required code is already in UCableComponent, it’s just not used.
Create a child C++ class from UCableComponent called ULocalCableComponent, and have this as .h:
// 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;
};
and .cpp:
// 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();
};
Hey, I’m trying to do this, but on a skeletal mesh. I tried your solution but it didn’t work, do you have any idea what I should do instead to make it work?