获取Actor里的某个Component的某个值

MyBlueprintFunctionLibrary.cpp

bool UMyBlueprintFunctionLibrary::FindComponentValue(AActor* InActor, /*UClass*/TSubclassOf<UActorComponent> InComponentClass,FString InComponentStr,FName InPropertyName)
{
    if (InActor == nullptr) return false;

/*    //获取Actor的类
    UClass* ActorClass = InActor->GetClass();
    if (ActorClass == nullptr) return false;

    //获取Actor的Components

    //for循环Components,找到名称和InComponentStr对应的Component

        //找到属性名称和InPropertyName对应的值并打印
        //如何想要设置这个值,应该如何扩展
        return true;*/

	if (!ComponentClass) return false;
	UActorComponent* FoundComponent = InActor->GetComponentByClass(ComponentClass);
	if (FoundComponent == nullptr) return false;
	FProperty* Property = FoundComponent->GetClass()->FindPropertyByName(InPropertyName);
	if (Property == nullptr) return false;
      //....
}