Download

A few philosophical questions regarding AActor camera handling



/** Returns true if the actor contains an active camera component */

bool AActor::HasActiveCameraComponent() const
{
    if (bFindCameraComponentWhenViewTarget)
    {
        // Look for the first active camera component and use that for the view
        for (const UActorComponent* Component : OwnedComponents)
        {
            const UCameraComponent* CameraComponent = Cast<const UCameraComponent>(Component);
            if (CameraComponent)
            {
                if (CameraComponent->IsActive())
                {
                    return true;
                }
            }
        }
    }
    return false;
}

HasActiveCameraComponent() and HasActivePawnControlCameraComponent() are only considering OwnedComponents, but not InstanceComponents. Is that behavior documented anywhere? [HR][/HR]



/**
 * Calculate camera view point, when viewing this actor.
 *
 * @param    DeltaTime    Delta time seconds since last update
 * @param    OutResult    Camera configuration
 */

void AActor::CalcCamera(float DeltaTime, FMinimalViewInfo& OutResult)
{
    if (bFindCameraComponentWhenViewTarget)
    {
        // Look for the first active camera component and use that for the view
        TInlineComponentArray<UCameraComponent*> Cameras;
        GetComponents<UCameraComponent>(/*out*/ Cameras);

        for (UCameraComponent* CameraComponent : Cameras)
        {
            if (CameraComponent->IsActive())
            {
                CameraComponent->GetCameraView(DeltaTime, OutResult);
                return;
            }
        }
    }

    GetActorEyesViewPoint(OutResult.Location, OutResult.Rotation);
}


Here instead of iterating over components like in HasActiveCameraComponent() we inspect every component and save pointers to cameras, then ditch all but the first active camera. Is it arbitrary or has something to do with garbage collection references? [HR][/HR]