Last active
November 7, 2024 07:02
-
-
Save timoxley/36a5e86662707d1b1acaa13958f4d4fd to your computer and use it in GitHub Desktop.
Quick GetValidComponentByClass for Blueprint, with exec pins based on validity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UCLASS() | |
class MY_API UMyUtils : public UBlueprintFunctionLibrary | |
{ | |
GENERATED_BODY() | |
public: | |
UFUNCTION( | |
BlueprintCallable, | |
meta = ( | |
ComponentClass = "/Script/Engine.ActorComponent", | |
DeterminesOutputType = "ComponentClass", | |
ExpandBoolAsExecs = "IsComponentValid" | |
) | |
) | |
static UActorComponent* GetValidComponentByClass( | |
AActor* Actor, | |
TSubclassOf<UActorComponent> const ComponentClass, | |
bool& IsComponentValid | |
) | |
{ | |
IsComponentValid = false; | |
if (!IsValid(Actor)) { return nullptr; } | |
if (const auto Component = Actor->FindComponentByClass(ComponentClass)) | |
{ | |
IsComponentValid = true; | |
return Component; | |
} | |
return nullptr; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment