27 lines
808 B
C++
27 lines
808 B
C++
// Copyright PICO Technology Co., Ltd. All rights reserved.
|
|
// This plugin incorporates portions of the Unreal® Engine. Unreal® is a trademark or registered trademark of Epic Games, Inc. in the United States of America and elsewhere.
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#pragma once
|
|
|
|
namespace PXRUtility
|
|
{
|
|
template <typename T>
|
|
T* FindComponentByName(AActor* Actor, const FName& ComponentName)
|
|
{
|
|
if (IsValid(Actor) && (ComponentName != NAME_None))
|
|
{
|
|
TArray<T*> ComponentsOfType;
|
|
Actor->GetComponents<T>(ComponentsOfType);
|
|
T** FoundComponent = ComponentsOfType.FindByPredicate([Name = ComponentName.ToString()](T* Component) { return Component->GetName().Equals(Name); });
|
|
|
|
if (FoundComponent != nullptr)
|
|
{
|
|
return *FoundComponent;
|
|
}
|
|
}
|
|
|
|
return nullptr;
|
|
}
|
|
}
|