(c++ plugin) UProperty FString problem.

public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “General”)
FString Path01;

In UE5.2 IDE, I set the value of Path01.
Path01 = “/Script/Engine.Texture2D’/Game/WebCam/Images/cat.cat’”;

Here is the code.
if (Path01.Len() > 0)
{
char* s = TCHAR_TO_ANSI(Path01);
(METHOD #1) Tex01 = Cast(StaticLoadObject(UTexture2D::StaticClass(), NULL, (TCHAR
)(s)));

(METHOD #2) Tex01 = Cast(StaticLoadObject(UTexture2D::StaticClass(), NULL, TEXT(“/Script/Engine.Texture2D’/Game/WebCam/Images/cat.cat’”)));
}

Method #1 : Tex01 = NULL;
Method #2 : Tex01 = NOT NULL, it is set to cat image.

The value of “s” and the literal string in Method #2 are identical.
So I don’t understand what I am doing wrong…is the casting wrong?

Hi martinortiz,

try this instead:

...(UTexture2D::StaticClass(),NULL,*Path01);

I get a compile error (no overload found)

Tex01 = Cast<UTexture2D>(UTexture2D::StaticClass(), NULL, *Path01);

however this seemed to work…

Tex01 = Cast<UTexture2D>(StaticLoadObject(UTexture2D::StaticClass(), NULL, *Path01));
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.