Download

Include custom actor component class

Hi guys, how would one go about using a component class in a blueprint function without exposing it as a function parameter?

my class is header is induced as UMaterial_Selector.


void UFunctions_LIBBPLibrary::MatSelector_ChangeMat(FName Tag, int MatID, TSubclassOf<UActorComponent> Component)
{
    //Get world.
    UWorld* World = GEngine->GetWorldContexts()[0].World();

    TArray<AActor*> FoundActors;
    UGameplayStatics::GetAllActorsWithTag(World, Tag, FoundActors);

    if (FoundActors.Num() != 0)

    {
        //Get actor component by class
        UActorComponent* FoundComponent = FoundActors[0]->FindComponentByClass(Component);


        if (FoundComponent != nullptr)
        {
            //Cast to Actor component.
            UMaterial_Selector* comp = Cast<UMaterial_Selector>(FoundComponent);

            UStaticMeshComponent* newmesh = FoundComponent->GetOwner()->FindComponentByClass<UStaticMeshComponent>();

            comp->ChangeMaterial(MatID, newmesh);
        }
    }

}