Skip to content

How to integrate a custom camera with Motion

Use this guide when your project uses its own camera component instead of UMotionCameraComponent.

Add the event bus

Add UMotionCameraEventBus to the character. Motion movement components broadcast camera curve and height events through this component.

Subscribe to events

Subscribe from your custom camera component during BeginPlay:

cpp
void UMyCustomCamera::BeginPlay()
{
    Super::BeginPlay();

    if (AActor* Owner = GetOwner())
    {
        if (UMotionCameraEventBus* EventBus = Owner->FindComponentByClass<UMotionCameraEventBus>())
        {
            EventBus->OnMotionCurveEvent.AddDynamic(this, &UMyCustomCamera::HandleCurveEvent);
            EventBus->OnCameraHeightEvent.AddDynamic(this, &UMyCustomCamera::HandleHeightEvent);
        }
    }
}

Handle curve events

cpp
void UMyCustomCamera::HandleCurveEvent(const FMotionCurve& Curve, EMotionCameraAction Action)
{
    if (ACharacter* Character = Cast<ACharacter>(GetOwner()))
    {
        if (!Character->IsLocallyControlled())
        {
            return;
        }
    }

    switch (Action)
    {
        case EMotionCameraAction::Add:
            AddMyCurveEffect(Curve);
            break;
        case EMotionCameraAction::Remove:
            RemoveMyCurveEffect(Curve.Identifier);
            break;
        case EMotionCameraAction::Pause:
            PauseMyCurveEffect(Curve.Identifier);
            break;
        case EMotionCameraAction::Resume:
            ResumeMyCurveEffect(Curve.Identifier);
            break;
    }
}

Handle height events

cpp
void UMyCustomCamera::HandleHeightEvent(float TargetHeight, bool bInterpolate)
{
    SetMyCameraHeight(TargetHeight, bInterpolate);
}

Only apply local camera effects for the locally controlled character.

Motion - Advanced First Person Character Controller