Camera Shake C++ not working


I’ve tried to move my code from blueprint into C++ for camera shake, but apparently it’s not working

Here’s the code

UCameraShake* CameraShake = ConstructObject<UCameraShake>(UCameraShake::StaticClass());
CameraShake->OscillationDuration = -1.0f; //negative value will run forever
CameraShake->RotOscillation.Pitch.Amplitude = 1.0f;
CameraShake->RotOscillation.Pitch.Frequency = 0.5f;
CameraShake->RotOscillation.Pitch.InitialOffset = EInitialOscillatorOffset::EOO_OffsetRandom;

CameraShake->RotOscillation.Yaw.Amplitude = 1.0f;
CameraShake->RotOscillation.Yaw.Frequency = 0.5f;
CameraShake->RotOscillation.Yaw.InitialOffset = EInitialOscillatorOffset::EOO_OffsetRandom;
Controller = GetWorld()->GetFirstLocalPlayerFromController()->PlayerController;
Controller->ClientPlayCameraShake(CameraShake->GetClass(), 1.0f);

Here’s the blueprint call and the testCameraShake class that is used on blueprint

I’ve seen answers on Camera Bob/Shake - Programming & Scripting - Unreal Engine Forums but the solution don’t reflect to my issues, checked on the values with debugger and see it populated correctly (I think)

Anything I missed? Thanks!

Turns out to make it work I only need to make changes on the CameraShake initialization it into this

CameraShake = UCameraShake::StaticClass()->GetDefaultObject<UCameraShake>();

I realize it from checking inside UCameraModifier_CameraShake::InitializeShake and seeing the value of SourceShake is not using the value I set up with

Just a notice. This code in broken in 4.8 and still need to be fixed…


Maybe I’m getting this wrong, but what you get with UCameraShake::StaticClass()->GetDefaultObject() is the class default object (CDO) from which all instances of UCameraShake are copied. Are you sure this is the way to go?