State Inheritance

PhantomCam cam-to-cam pose handoff protocol — CamPoseSnapshot universal trait, m_inheritState blend toggle, per-body-stage Get/Adopt implementations, ANGULAR vs POSITION mode, consumedAdoption gate.

State inheritance is a universal pose-handoff protocol: when the Cam Core transitions cam A → cam B, the matched Blend Profile entry may opt into inheritance via the InheritState flag. The outgoing cam publishes a CamPoseSnapshot; the incoming cam consumes it through its own kinematic model. The blend then reads as a small smooth drift instead of a swing.

Inheritance is body-only by design. Aim and additive stages don’t participate — the destination cam’s aim runs fresh on the inherited body pose.

 

Contents


The CamPoseSnapshot Trait

Universal pose-handoff struct. Runtime only — not serialized.

struct CamPoseSnapshot
{
    // Universal — every cam can produce this from its committed transform.
    AZ::Vector3  worldPos = Vector3::Zero();
    AZ::Vector3  worldFwd = Vector3::AxisY();

    // Source cam's resolved pivot in world space at the time of Get.
    // Orbit-style adopters use this to back-derive angular state in the
    // SOURCE cam's frame — preserves orientation even when the incoming
    // cam resolves a different pivot.
    AZ::Vector3  pivotPos      = Vector3::Zero();
    bool         pivotPosValid = false;

    AZ::EntityId pivotEntity;

    // Orbit-specific authored angular state. Populated by orbit-style Get
    // implementations; consumed by orbit-style Adopters directly, bypassing
    // back-derivation. Preserves A's exact yaw / pitch on B across different
    // orbit shapes — angular continuity wins over spatial back-fit.
    float        yawRad             = 0.0f;
    float        pitchRad           = 0.0f;
    bool         angularStateValid  = false;

    // Producer signal — set by TryGetPoseSnapshot when the snapshot is usable.
    bool         valid = false;

    static void Reflect(AZ::ReflectContext* context);
};

A snapshot may carry partial information. worldPos + worldFwd are always populated when valid is true. pivotPos is populated by bodies that publish a pivot (orbit-style, lead-follow). angularStateValid is set only by orbit-style bodies that publish authored yaw / pitch directly.


Opting In — The Blend Profile Toggle

Authored per-pair on PhantomBlend entries inside a .camblendprofile:

struct PhantomBlend {
    // ... other fields ...
    bool m_inheritState = false;
};

Default false so cinematic shots authored at specific poses land at those poses unless the author opts in. See Blend Profiles — Inherit State for the authoring surface.


The IBodyStage Virtuals

class IBodyStage {
public:
    // ... other interface ...

    // Default returns false — stage doesn't speak the protocol.
    virtual bool TryGetPoseSnapshot(CamPoseSnapshot& out)        const { return false; }
    virtual bool TryAdoptPoseSnapshot(const CamPoseSnapshot& in)       { return false; }
};

A body stage may implement only one side of the protocol. Static-shot bodies (OrbitBody) implement Get but leave Adopt at default false — their authored angles define their identity. Other body stages typically implement both.

Forwarders on the Phantom Camera

The component forwards both calls to the body slot:

bool GS_PhantomCameraComponent::TryGetPoseSnapshot(CamPoseSnapshot& out) const {
    if (IBodyStage* body = GetBody()) {
        return body->TryGetPoseSnapshot(out);
    }
    return false;
}

bool GS_PhantomCameraComponent::TryAdoptPoseSnapshot(const CamPoseSnapshot& in) {
    if (IBodyStage* body = GetBody()) {
        return body->TryAdoptPoseSnapshot(in);
    }
    return false;
}

Exposed on PhantomCameraRequestBus so the Cam Core can address cams uniformly.


Cam Core Handoff Site

Inside SetPhantomCam, after lastCam / currentCam are determined and before StartBlend:

const bool wantInherit = (bestBlend && bestBlend->m_inheritState
                          && lastCam.IsValid() && currentCam.IsValid());

if (wantInherit)
{
    CamPoseSnapshot snap;
    bool gotPose = false;
    PhantomCameraRequestBus::EventResult(gotPose, lastCam,
        &PhantomCameraRequests::TryGetPoseSnapshot, snap);

    if (gotPose && snap.valid)
    {
        bool adopted = false;
        PhantomCameraRequestBus::EventResult(adopted, currentCam,
            &PhantomCameraRequests::TryAdoptPoseSnapshot, snap);
        (void)adopted;
    }
}

// ... then StartBlend.

The handoff runs before StartBlend, so by the time the blend captures source and destination poses, the destination cam’s body has already adopted the seed pose. The blend then interpolates from the source’s literal position to the destination’s already-inherited pose.

Bodies that don’t speak the protocol (or that reject the inbound pose) return false; the handoff is silent and the blend proceeds normally.


Per-Variant Implementations

DefaultFollowBody

SideBehavior
GetNot implemented (default false).
AdoptNot implemented (default false).

Inheritance into a Default Follow falls through to the Blend Profile’s visual bridge.

OrbitBody (Get-only)

SideBehavior
GetPublishes the cleanest snapshot in the framework. worldPos = m_idealPosition, worldFwd toward cached pivot, pivotPos = m_lastPivot (post-offset target, pre-orbit), AND direct authored yawRad / pitchRad + angularStateValid = true. Orbit-style adopters receive ANGULAR-mode handoff with no back-derivation.
AdoptDisabled (default false). The authored yaw / pitch define the static shot’s identity; accepting inbound pose would defeat author intent.

DynamicOrbitBody (full Get + Adopt)

Get:

out.worldPos          = m_idealPosition;
out.worldFwd          = (m_lastResolvedPivot - m_idealPosition).GetNormalizedSafe();
out.pivotPos          = m_lastResolvedPivot;
out.pivotPosValid     = true;
out.pivotEntity       = m_lastResolvedPivotEntity;
out.yawRad            = m_targetYaw;
out.pitchRad          = m_targetPitch;
out.angularStateValid = true;
out.valid             = true;
return true;

Requires a committed pose AND a cached pivot. First-tick adopters that haven’t ticked yet return false.

Adopt stashes the snapshot. The actual derivation happens in the next Evaluate where pivot resolution has run:

if (m_hasPendingAdoption && m_orbitShape.Get())
{
    if (m_pendingAdoption.angularStateValid)
    {
        // ANGULAR mode (preferred). Inherit raw yaw / pitch directly.
        m_targetYaw   = WrapYawToPi(
            ShortestYawTarget(m_targetYaw, m_pendingAdoption.yawRad));
        m_targetPitch = AZ::GetClamp(m_pendingAdoption.pitchRad,
                                     CameraOrbitShape::kPitchAtLow,
                                     CameraOrbitShape::kPitchAtHigh);
    }
    else
    {
        // POSITION mode (fallback). Back-derive yaw from worldPos.
        const AZ::Vector3 referencePivot = m_pendingAdoption.pivotPosValid
            ? m_pendingAdoption.pivotPos
            : pivot;
        const AZ::Vector3 off = m_pendingAdoption.worldPos - referencePivot;

        const float yawObserved    = std::atan2(off.GetY(), off.GetX());
        const float radiusObserved = std::sqrt(off.GetX()*off.GetX() + off.GetY()*off.GetY());
        const float heightObserved = off.GetZ();

        m_targetYaw   = WrapYawToPi(ShortestYawTarget(m_targetYaw, yawObserved));
        m_targetPitch = FindPitchOnShape(*m_orbitShape.Get(), radiusObserved, heightObserved);
    }

    m_idealPosition       = m_pendingAdoption.worldPos;   // seed at adopted pose
    m_hasIdeal            = true;
    consumedAdoption      = true;
    m_hasPendingAdoption  = false;
}

The ANGULAR path is preferred — it preserves authored angular state across different orbit shape assets, which the position back-derivation cannot. The POSITION path is the safety net for source bodies that don’t publish angular state.

LeadingFollowBody (facing-seeded standoff)

Get returns m_idealPosition, world-forward toward cached target, pivotPos = m_lastTargetPoint. No angular state — lead-follow has no degree of freedom other than position-in-band.

Adopt stashes the snapshot. The consume block in Evaluate reads source worldFwd, flattens to the XY plane, and seeds the cam at band-natural standoff distance:

AZ::Vector3 inboundFwd = m_pendingAdoption.worldFwd;
inboundFwd.SetZ(0.0f);
inboundFwd = inboundFwd.GetNormalizedSafe();
if (inboundFwd.GetLengthSq() < epsilon)
    inboundFwd = GetHorizontalForward(stageTargetTM);   // fallback

const float seedDist = AZ::Lerp(m_innerRadius, m_outerRadius, 0.6f);
m_idealPosition = targetPoint - inboundFwd * seedDist;

m_hasIdeal           = true;
m_idleTimer          = 0.0f;
m_hasLastTarget      = true;
consumedAdoption     = true;
m_hasPendingAdoption = false;

Why facing-seeded, not position-seeded? Lead-follow is heading-agnostic. Seeding with the source’s literal worldPos would lock the cam at an off-band angle, defeating the body’s authored intent. The cam inherits the source’s facing at this body’s preferred standoff. Z naturally lands at targetPoint.Z (inboundFwd is XY-flattened) — a from-below source produces a band-natural pose, not stuck-below framing.

TrackBody (path-projection with threshold)

Get returns m_idealPosition plus world-forward toward cached target. No angular state, no pivot — the path is the kinematic reference, not a point.

Adopt stashes. The consume block projects the source’s position onto the spline and rejects when the source sits too far from the path:

EnsureSplineResolved();
if (!m_spline) { m_hasPendingAdoption = false; return; }

AZ::Vector3 nearestWorld;
const float dist = m_spline->FindClosestWorldPoint(
    m_pendingAdoption.worldPos, nearestWorld, /*outT*/);

if (dist > m_adoptionPathThreshold)
{
    // Source sits too far from path — reject, fall back to plain blend.
    m_hasPendingAdoption = false;
    return;
}

m_idealPosition  = m_pendingAdoption.worldPos;
m_springVelocity = AZ::Vector3::CreateZero();
m_hasIdeal       = true;
consumedAdoption = true;
m_hasPendingAdoption = false;

m_adoptionPathThreshold is authored on the TrackBody (default 5.0 m). Prevents teleport-snap when the source cam sits well off the dolly’s path.


The consumedAdoption Gate

Problem: With ctx.snapThisFrame = true on activation, every body’s damping clause snap-clobbers m_idealPosition = desiredPos, discarding the adoption seed. Symptom: cam jerks to its natural ideal then blends from there.

Fix: The snap-on-activation block in every body is gated on !consumedAdoption:

if ((ctx.snapThisFrame || !m_hasIdeal) && !consumedAdoption)
{
    // Snap-seed path. Skipped when adoption already placed m_idealPosition.
}

Adoption-tick uses standard damping from the adopted seed, not snap-seed. When inheritance fires, the seed pose is preserved through the activation tick.


Authoring Gotcha — Matched but Not Inheriting

If m_inheritState is unchecked on a matched blend pair, the destination cam falls through to its snap-on-activation seed instead of consuming the source’s pose. Symptoms vary by body type but all point to the same root cause:

BodySymptom
LeadingFollowBody“Cam orients behind player’s travel direction regardless of source facing.” The snap block uses GetHorizontalForward(stageTargetTM) = target’s BasisY.
DynamicOrbitBody / OrbitBodyCam swings to authored yaw / pitch then blends from there.
TrackBodyDolly starts at its untouched starting spline parameter.

The fix is data-side: check the Inherit State flag on the matched blend entry inside the .camblendprofile asset.

If diagnostic prints are added during debugging, the smoking gun looks like:

Handoff: from=OrbitCam to=LeadCam inherit=0 (matched=1)

matched = 1, inherit = 0 means the blend pair IS in the asset, but m_inheritState is unchecked on it.


Adoption Coverage Matrix

Body VariantGetAdoptSource publishes
DefaultFollowBody
OrbitBody (static)— (Get-only)worldPos, worldFwd, pivotPos, full angular
DynamicOrbitBody✓ (ANGULAR / POSITION)worldPos, worldFwd, pivotPos, full angular
LeadingFollowBody✓ (facing-seeded standoff)worldPos, worldFwd, pivotPos (= target), no angular
TrackBody✓ (path-project + threshold)worldPos, worldFwd, no angular, no pivot

See Also

Related PhantomCam pages:

Basics-side authoring guide:


Get GS_PhantomCam

GS_PhantomCam — Explore this gem on the product page and add it to your project.