In Blueprint I know I can do something like this to load an image, for example:
and it works without any problem.
The problem is that I’m not interested in it for “n” reasons that are beyond the scope of this post.
In my Code I have something like this:
const FString initialBackgroundPath = FPaths::ProjectDir() + TEXT("Content/...") +Obj->GetIconName();
if (FPaths::FileExists(initialBackgroundPath)) {
TSoftObjectPtr<UTexture2D> Icon = TSoftObjectPtr<UTexture2D>(FSoftObjectPath(initialBackgroundPath));
Obj->SetIcon(Icon);
} else {
UE_LOG(LogTemp, Warning, TEXT("File does not exist: %s"), *initialBackgroundPath);
Obj->SetIcon(NULL);
}
The debugger tells me “nullptr”, so that seems to be the problem here
There may be a better way to do it in C++ or something and I don’t know about it.
Yes I have thought about Using UImage. But first I prefer to solve it by Texture2D.
Does the code I provided correctly pick up the image or does it really have to be done another way?
Note: The format is .png