Download

Please Stop Truncating "Component" in FName

I’ve noticed recently that in many cases when I am developing a system, I will use a SceneComponent attached to an actor.
When I go to debug my work, the “Component” aspect of my class names gets inexplicably truncated off, leaving me in a very confused place.
This just recently happened with this snippet:



FName HitComponent = HitOut.Component->GetFName();

if (HitOut.Component->IsA(UInteractionWidget::StaticClass()))
{
      GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Cyan, FString::Printf(TEXT("!!!!!!!!!!!!!!!!! Component is: %s"), *HitComponent.ToString()));
}
else
{
      GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Cyan, FString::Printf(TEXT("Component is: %s"), *HitComponent.ToString()));
}


Now, the else block will print “Component is: Interaction Widget”! Because the component that it is hitting is a UInteractionWidgetComponent.
So I was dealing with code that would check if the hit component was an InteractionWidget, which would return false and then tell me what it was an InteractionWidget.

All because “Component” is truncated off of names. Not helpful.

Now I have team members asking me if they can name things “InteractionWidgetComp” or worse, “InteractionWidgetModule” just so they can get around this implementation.

Please stop truncating class names.

Hi Tiskahar,

I was just looking at this, and I have a question for you. If you were to change the condition in your if statement to [FONT=Times New Roman]if (HitOut.Component->IsA(UInteractionWidgetComponent::StaticClass())), does it work then? I did a quick and dirty test with this using an Actor with a UStaticMeshComponent, and when I tested for [FONT=Times New Roman]IsA(UStaticMesh::StaticClass()), it would always fail as you described. However, if I instead tested for [FONT=Times New Roman]IsA(UStaticMeshComponent::StaticClass()), then it would always succeed when the trace hit the mesh.

If that doesn’t work for you, I can dig into this a bit more tomorrow.

Tim