Hi, I try to read value of variable, but got something other.
Perhaps someone will be kind enough to explain to me what I do wrong.
Here a small class, with one variable and method reading it.
#pragma once
#include "Object.h"
#include "MyObject.generated.h"
UCLASS(BlueprintType, Blueprintable)
class PROPTEST_API UMyObject : public UObject
{
GENERATED_BODY()
public:
UMyObject();
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = "Test")
int intVariable = 42;
UFUNCTION(BlueprintCallable, Category = "Test")
void readVarable();
protected:
void TraceInt(int n);
void TraceText(FString str);
};
#include "propTest.h"
#include "MyObject.h"
UMyObject::UMyObject(){}
void UMyObject::readVarable()
{
FName variableName = TEXT("intVariable");
UProperty* property = GetClass()->FindPropertyByName(variableName);
const UNumericProperty* intProperty = Cast<const UNumericProperty>(property);
int readValue = intProperty->GetSignedIntPropertyValue(this);
TraceInt(readValue);
}
void UMyObject::TraceText(FString fstring)
{
UE_LOG(LogTemp, Log, TEXT("%s"), *fstring);
}
void UMyObject::TraceInt(int n)
{
FString fstring = FString::FromInt(n);
TraceText(fstring);
}