KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
FComponentHelper.h
이 파일의 문서화 페이지로 가기
1// Copyright (c) 2025 Doppleddiggong. All rights reserved. Unauthorized copying, modification, or distribution of this file, via any medium is strictly prohibited. Proprietary and confidential.
6#pragma once
7
8#include "CoreMinimal.h"
9#include "GameFramework/Actor.h"
10#include "Components/ActorComponent.h"
11#include "Kismet/GameplayStatics.h"
12
14{
15 template<typename T>
16 static T* LoadAsset(const TCHAR* Path)
17 {
18 static_assert(std::is_base_of<UObject, T>::value, "T must derive from UObject");
19
20 ConstructorHelpers::FObjectFinder<T> Obj(Path);
21 return Obj.Succeeded() ? Obj.Object.Get() : nullptr;
22 }
23
24 template<typename T>
25 static TSubclassOf<T> LoadClass(const TCHAR* Path)
26 {
27 static_assert(std::is_base_of<UObject, T>::value, "T must derive from UObject");
28
29 ConstructorHelpers::FClassFinder<T> Finder(Path);
30 return Finder.Succeeded() ? Finder.Class : nullptr;
31 }
32
33 template<typename T>
34 static T* FindComponentByName(AActor* Owner, const FName& ComponentName)
35 {
36 if (!IsValid((Owner)))
37 {
38 return nullptr;
39 }
40
41 TArray<T*> FoundComponents;
42 Owner->GetComponents(FoundComponents);
43
44 for (T* Component : FoundComponents)
45 {
46 if (Component && Component->GetFName() == ComponentName)
47 {
48 return Component;
49 }
50 }
51 return nullptr;
52 }
53 template<typename T>
54 static T* FindComponentByNameRecursive(AActor* Owner, const FName& ComponentName)
55 {
56 if (!IsValid((Owner)))
57 return nullptr;
58
59 TArray<UActorComponent*> Components;
60 Owner->GetComponents(Components, true);
61
62 for (UActorComponent* Component : Components)
63 {
64 if (Component && Component->GetFName() == ComponentName)
65 {
66 return Cast<T>(Component);
67 }
68 }
69 return nullptr;
70 }
71
72 template<typename T>
73 static TArray<T*> GetAllOfClass(UWorld* World)
74 {
75 static_assert(TIsDerivedFrom<T, AActor>::IsDerived, "T must derive from AActor");
76
77 TArray<T*> Result;
78
79 if (!World)
80 return Result;
81
82 TArray<AActor*> FoundActors;
83 UGameplayStatics::GetAllActorsOfClass(World, T::StaticClass(), FoundActors);
84
85 for (AActor* Actor : FoundActors)
86 {
87 if (T* Casted = Cast<T>(Actor))
88 {
89 Result.Add(Casted);
90 }
91 }
92
93 return Result;
94 }
95};
static T * FindComponentByNameRecursive(AActor *Owner, const FName &ComponentName)
static TSubclassOf< T > LoadClass(const TCHAR *Path)
static T * LoadAsset(const TCHAR *Path)
static T * FindComponentByName(AActor *Owner, const FName &ComponentName)
static TArray< T * > GetAllOfClass(UWorld *World)