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.