Шаблон-функция для запуска лямбды по классу

Старая версия

	
bool CheckClass(UObject* Object, UClass* TestClass)
{
	bool bReturn = Object->GetClass() == TestClass || Object->GetClass()->IsChildOf(TestClass);
	return bReturn;
}

		
template<class... ClassType, class... OperationType>
void DoByClass(UObject*& Obj, OperationType&&... Operations)
{
	auto CheckAndDo = [&](auto&& CastedObj, auto&& InOperationType) {
		check(CastedObj);
		InOperationType(CastedObj);
		return true;
	};
	[](auto&&...) {}((CheckClass(Obj, ClassType::StaticClass()) ? CheckAndDo(Cast<ClassType>(Obj), Operations) : nullptr, nullptr)...);
}
		
		DoByClass<AActor, UBlueprint, UStaticMesh>(
		    CashedObj,
		    [&](auto ObjCasted) {
			    auto NewActor = GetWorld()->SpawnActor<AActor>(ObjCasted->GetClass());
			    VisualActor = NewVisualComponent;
		    },
		    [&](auto ObjCasted) {
			    CashedObj = ObjCasted->GeneratedClass->GetDefaultObject<AActor>();
		    },
		    [&](auto ObjCasted) {
			    auto NewActor = GetWorld()->SpawnActor<UStaticMeshComponent>();
			    NewActor->SetStaticMesh(ObjCasted);
			    NewActor->Collisio
			        VisualActor
			        = NewVisualComponent;
		    });

Last updated