What is the difference between GetActorNameOrLabel() and GetName()?

Hi,
I tried to jump ahead and do the start of the lecture before it was demonstrated. I used:

AActor* Owner = GetOwner();
UE_LOG(LogTemp, Warning, TEXT(“Owner Actor Name: %s”), *Owner->GetName());

This gives an answer of:

LogTemp: Warning: Owner Actor Name: StaticMeshActor_525

When I changed my code to use GetActorNameOrLabel() instead of GetName(), the output changes to : LogTemp: Warning: Owner Actor Name: SM_CastleWallEntranceDoor.

Why does GetName() not work here? I have looked for the name StaticMeshActor_525 and I can not find it on the object so I have no idea where it is coming from.

Any help would be appreciated.

Thanks

An actor label is an editor only property and is what you see in the outliner.

If you right click the header you can enable ID Name and that is the actor’s name. GetActorNameOrLabel will return the label if it exists otherwise it will return the name. IMO it makes more sense to be the other way round i.e. GetActorLabelOrName.

The definition is just

public:
	const FString GetActorNameOrLabel() const
	{
#if WITH_EDITORONLY_DATA || (!WITH_EDITOR && ACTOR_HAS_LABELS)
		if (!ActorLabel.IsEmpty())
		{
			return ActorLabel;
		}
#endif
		return GetName();
	}
1 Like

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

Privacy & Terms