How to extract Camera Shake relative offset that is currently applied at given frame.

I have a use case where I’d like to quantify the relative shake being added on a given frame from a given CameraShake class. So far I’ve researched enough to understand that the CameraShake returns a class where I can query details like the kind of shake that it is, stop and start it, and so on…but there is no way to query what the current value of it is, presumably because it’s happening on its own thread.

Is there a way to know, ideally in blueprint, what the 3D offset is from a single CameraShake source?

Note that my project contains multiple things influencing the camera at any given time, so a simple hack like checking the difference between the Controller and the CameraManager’s transforms would not be sufficient in this case. I would like to know the relative offset being applied by a specific CameraShake instance, on a given frame.

Steps to Reproduce

Hi [mention removed]​,

I don’t think there is a built-in way to extract the delta transforms of the camera between frames. I have not found a way to do this in Blueprint, but you can achieve this in C++ without that much work. I’ll write out the solution that I found out that does the job if you don’t want a hacky solution.

Unreal Engine source code has a C++ class called UCameraModifier, which allows developers to make any modifications to the final transform of the camera. For the CameraShake system, Unreal uses the UCameraModifier_CameraShake class that inherits from UCameraModifier.

What you can do, is create a new UCameraModifier_CameraShakeModifier that overrides the ModifyCamera function. This function allows you to extract the delta between frames of the camera:

MyCameraModifier.h

`UCLASS()
class TPP_54_API UMyCameraModifier : public UCameraModifier_CameraShake
{
GENERATED_BODY()

public:
UMyCameraModifier(const FObjectInitializer& ObjectInitializer);

FVector OldLocation;

virtual bool ModifyCamera(float DeltaTime, FMinimalViewInfo& InOutPOV) override;
};`

MyCameraModifier.cpp

`UMyCameraModifier::UMyCameraModifier(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}

bool UMyCameraModifier::ModifyCamera(float DeltaTime, FMinimalViewInfo& InOutPOV)
{

UE_LOG(LogTemp, Warning, TEXT(“PreLocation: %s”), *OldLocation.ToString())

//Delta OldLocation - InOutPov.Location(New frame location)
FVector DeltaLocation = OldLocation - InOutPOV.Location;

//Update the frame location
OldLocation = InOutPOV.Location;

UE_LOG(LogTemp, Warning, TEXT(“DeltaLocation: %s”), *OldLocation.ToString())

UE_LOG(LogTemp, Warning, TEXT(“PostLocation: %s”), *OldLocation.ToString())

return Super::ModifyCamera(DeltaTime, InOutPOV);
}`

This class inherits the default behaviour of the UCameraModifier_CameraShake, and also enables you to extract the delta of the camera. To use your Camera Modifier instead of the default one, you need to register it:

`void AMyPlayerController::BeginPlay()
{
Super::BeginPlay();
if (PlayerCameraManager)
{
// Find existing shake modifier
UCameraModifier_CameraShake* DefaultMod =
Cast<UCameraModifier_CameraShake>(
PlayerCameraManager->FindCameraModifierByClass(UCameraModifier_CameraShake::StaticClass())
);
if (DefaultMod)
{
PlayerCameraManager->RemoveCameraModifier(DefaultMod);
}

// Add yours
UMyCameraModifier* MyMod =
Cast(
PlayerCameraManager->AddNewCameraModifier(UMyCameraModifier::StaticClass()));

PlayerCameraManager->PostInitializeComponents();
if (MyMod)
{
MyMod->Priority = DefaultMod ? DefaultMod->Priority : 0;
}
}
}`

With these changes you can extract the real delta of the camera without a hacky solution or modifying the engine source code.

Let me know if this did the job.

Best,

Joan