Download

BlueprintAutocast meta specifier not working

I am trying to get the BlueprintAutocast working. From my understanding this is how you can automatically cast in blueprint from type to another with a special node.

Here is my test code where I am attempting to cast the UStruct FCoordinate to a FString.

using Unreal 4.21.2

.h


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "Coordinate.generated.h"

/**
 * 
 */


USTRUCT(BlueprintType)
struct GAME_API FCoordinate
{
    GENERATED_BODY()


    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Coordinate)
    int32 X;

    UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Coordinate)
    int32 Y;

    FCoordinate(int32 XValue = 0, int32 YValue = 0) : X(XValue), Y(YValue) {}

    static const FCoordinate Origin;

    FString ToString() const
    {
        return FString::Printf(TEXT("(X=%i,Y=%i)"), X, Y);
    }
};


/**
 * Helper functions for dealing with Directions.
 */
UCLASS()
class GAME_API UCoordinateStatics : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()

    /** Converts a Coordinate value to a string */
    UFUNCTION(BlueprintPure, meta = (DisplayName = "ToString (Coordinate)", CompactNodeTitle = "->", BlueprintAutocast), Category = "Utilities|String")
    static FString CoordinateToString(FCoordinate Coordinate);
};



and the .cpp


// Fill out your copyright notice in the Description page of Project Settings.

#include "Coordinate.h"


const FCoordinate FCoordinate::Origin(0, 0);


FString UCoordinateStatics::CoordinateToString(FCoordinate Coordinate)
{
    return Coordinate.ToString();
}


The result I am currently getting is that I can’t directly connect the FCoordinate variable into an FString variable and have the CoordinateToString node be generated automatically. I can however create the node individually and link everything together.

picture attached showing connection is not available.

Thanks for help.

OK I solved my problem. I can now connect FCoordinates to FStrings and get it working generating inbetween nodes properly.

Posting in hoping this will help someone in the future.

Found a snipit in. EdGraphSchema_K2.cpp


static bool IsAutocastFunction(const UFunction* Function)
    {
        const FName BlueprintAutocast(TEXT("BlueprintAutocast"));
        return Function
            && Function->HasMetaData(BlueprintAutocast)
            && Function->HasAllFunctionFlags(FUNC_Static | FUNC_Native | FUNC_Public | FUNC_BlueprintPure)
            && Function->GetReturnProperty()
            && GetFirstInputProperty(Function);
    }

So my issue was that my function wasn’t made public.

Here is the alteration.
notice I added the “public:” scope identifier.


UCLASS()
class GAME_API UCoordinateStatics : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()
public:
    /** Converts a Coordinate value to a string */
    UFUNCTION(BlueprintPure, meta = (DisplayName = "ToString (Coordinate)", CompactNodeTitle = "->", BlueprintAutocast), Category = "Utilities|String")
    static FString CoordinateToString(FCoordinate Coordinate);
};