Call a C++ function through blueprints? / Update Mesh Distance Fields with origin shifting

Ok–here goes :astonished:
All I know is that it will compile and not crash (for me).

In the file BlueprintFunctions.h, between lines 16 and 17, put:

    public:
    UFUNCTION(BlueprintCallable)
    static void UpdateDistanceFields();

And, add this to the end of BlueprintFunctions.cpp:

void UBlueprintFunctions::UpdateDistanceFields() {
        ForEachObjectOfClass(UPrimitiveComponent::StaticClass(),
                [](UObject* Object)
                {
                        UPrimitiveComponent* Comp = Cast<UPrimitiveComponent>(Object);
                        if (IsValid(Comp) && Comp->IsRegistered()) {
                                Comp->GetScene()->UpdatePrimitiveDistanceFieldSceneData_GameThread(Comp);
                        }
                }
        ,true, RF_ClassDefaultObject, EInternalObjectFlags::None);
}

After compiling, there should be a new blueprint node called ā€œUpdateDistanceFieldsā€.

Hope it works

1 Like