Problem with getting Sphere Component Radius in C++

Hi, I’m not sure if this is an engine bug or something, but I just recently transferred a project from Unreal Engine 4.27 to 5.1, and while most still worked I found one problem with trying to get the radius of a USphereComponent. Functions such as GetScaledSphereRadius and GetUnscaledSphereRadius only seem to return 0. This is only a problem in C++, and does not happen with the blueprints equivalent of these functions where the correct value is given. Again this is code directly ported from a previous version of Unreal where everything worked fine, I’m not sure if this is a bug or there is a new way of doing things, any information would be appreciated.

The Blueprint’s function and the C++ function is both using the same function which is located in “/Engine/Source/Runtime/Engine/Classes/Components/SphereComponent.h”

This is the extract of the definition in UE5.11:

FORCEINLINE float USphereComponent::GetScaledSphereRadius() const
{
	return SphereRadius * GetShapeScale();
}

FORCEINLINE float USphereComponent::GetUnscaledSphereRadius() const
{
	return SphereRadius;
}

So I suspect you couldn’t set the member variable “SphereRadius” properly when defining the component or something. And as for the blueprints, you achieved this successfully for some reason. So why don’t you examine the differences between the two declarations or around there?

I’m not sure if there is a difference, the code is:

	GLog->Log(FString::Printf(TEXT("Scaled Sphere Radius %d"), HeadBound->GetScaledSphereRadius()));

And the blueprint is:


It’s the same function on the same variable. In code ‘Headbound’ is a USphereComponent, and in blueprints it’s labelled as a Sphere Collision Object, so I don’t know if these are different, I have no experience with things changing type when taken into blueprints if this is the case.

Hi PolarPandar,

GetScaledSphereRadius() returns a float - change the “%d” to “%f” in the logging of it.

1 Like

Yeah… Oops. Thank you-
Unfortunately it just changes which function broke during the transition between engine versions from the original code I was working on to a sphere trace, so I think I need to do more testing.

It’s been a long day…

1 Like