GetName();
To find the owner of the component.
Ex: When inserting a component in the chair, a reference to the chair will be returned.
From Unreal Engine API Reference:
UObjectBaseUtility::GetName
Syntax: FString GetName()
Remarks
Returns the name of this object (with no path information)
OK, Follow this steps:
1) File -> New Project -> C++ -> Basic Code -> With Starter Content
2) Inside MinimalDefault Map select one chair and pick Add Component Button.
3) Choose New C++ Component
4) Choose Actor Component Class and click em Next Button
5) In Visual Studio inside NewActorComponent.cpp insert code below in BeginPlay() function
UNewActorComponent::UNewActorComponent()
{
PrimaryComponentTick.bCanEverTick = true;
FString ObjectName = GetOwner()->GetName();
UE_LOG(LogTemp, Warning, TEXT("ObjetctName: %s"), *Objectname);
}
6) Show Log Window in Unreal Engine 4
Log Windows
7) Compile!
8) See Results in Log Window
logwindowresults
Below Complete Code. It Works! Enjoy!
#include "NewActorComponent.h"
#include "Runtime/Engine/Classes/GameFramework/Actor.h"
UNewActorComponent::UNewActorComponent()
{
PrimaryComponentTick.bCanEverTick = true;
}
void UNewActorComponent::BeginPlay()
{
Super::BeginPlay();
FString NameOfObject = GetOwner()->GetName();
UE_LOG(LogTemp, Warning, TEXT("Name is: %s"), *NameOfObject)
}
void UNewActorComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}