How to get current "Target Arm Length" of camera spring arm in Third Person Blueprint Template?

Hello,

In UE4 Third Person Blueprint Template, I am trying to get the value of Camera Boom’s Target Arm Length.

Using the very simple BP below, I am printing the value on screen at every tick.

Problem: When the Camera Boom collides with any object in scene, camera zoom in/out to the character just as expected. But, the value of Target Arm Length somehow never changes!

Question: Is this normal? If yes, what parameter should I check for getting the distance between Camera Boom and the character?

Same question also asked in here, and still remains unanswered:

Hi,

from my undestanding the code, the Target Arm Length always remain the same, but take a look on the:

void USpringArmComponent::UpdateDesiredArmLocation(bool bDoTrace, bool bDoLocationLag, bool bDoRotationLag, float DeltaTime)

This function updates protected members (RelativeSocketLocation, RelativeSocketRotation) of spring arm component:

// Form a transform for new world transform for camera
FTransform WorldCamTM(DesiredRot, ResultLoc);
// Convert to relative to component
FTransform RelCamTM = WorldCamTM.GetRelativeTransform(ComponentToWorld);

// Update socket location/rotation
RelativeSocketLocation = RelCamTM.GetLocation();
RelativeSocketRotation = RelCamTM.GetRotation();

UpdateChildTransforms();

And they are exposed in BP with “GetSocketTransform” function. You can try call “GetSocketTransform” with RTS_Component parameter and obtain position then compute length of this vector.

FTransform USpringArmComponent::GetSocketTransform(FName InSocketName, ERelativeTransformSpace TransformSpace) const
{
	FTransform RelativeTransform(RelativeSocketRotation, RelativeSocketLocation);

	switch(TransformSpace)
	{
		case RTS_World:
		{
			return RelativeTransform * ComponentToWorld;
			break;
		}
		case RTS_Actor:
		{
			if( const AActor* Actor = GetOwner() )
			{
				FTransform SocketTransform = RelativeTransform * ComponentToWorld;
				return SocketTransform.GetRelativeTransform(Actor->GetTransform());
			}
			break;
		}
		case RTS_Component:
		{
			return RelativeTransform;
		}
	}
	return RelativeTransform;
}

Regards

Pierdek

Great idea!

Thank you very much Pierdek.

It works :slight_smile:

ps: Would you please convert your reply into an answer, so that I can click the checkmark to mark your answer accepted?

Can you add a blueprint function that returns the current length of the spring arm when it’s being pushed?

Here’s a way using blueprints. You could probably use a property of the SpringArm itself (instead of “Sphere”) to make this more portable.

1 Like

and you can use length squared to optimize it

1 Like


Thanks for this, i used it like this to keep my line trace the same distance when zooming in or out the camera.

There’s no way to get the current length of the Spring Arm. The Target Arm Length is exactly what it sounds like “A Target” so this value is unchanging when the spring arm is collapsed or not. The best you can do is get the distance between your mesh and the camera itself and if its vector length is lower than X value, then you can do whatever you want.
For example, I run this on tick to check if my camera is close to the player, and if it is, I dissolve the mesh:

DistanceToCamera

Additionally, you can test to see if the collision fix is being applied. This means while you can’t know the length of the Spring Arm, you can know if it is collapsed.

IsCollisionFixApplied

This will become true when the camera is colliding with the world. You can use this to make sure that you’re only fading out your character mesh when the camera is colliding and the distance is shorter than X. You might want to allow the player to zoom in on the character when it’s not colliding for example.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.